Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 1066E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main(){
int n,m,ans=0,sum=0,p=1;
cin>> n >>m;
string s,t;
cin>>s>>t;
for(int i=0;i<m;i++){
if(s[n-i-1]=='1'&& i<n)
sum=(sum+p)%mod;
if(t[m-i-1]=='1')
ans= ( ans + sum ) % mod;
p=(p*2)%mod;
}
cout<<ans<<endl;
}
36 changes: 36 additions & 0 deletions 1066F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PLL;
map<ll,vector<PLL> > mp;
ll dis(PLL a,PLL b){
return abs(a.first-b.first)+abs(a.second-b.second);
}
int main(){
ll n;
scanf("%lld",&n);
for(ll i=0;i<n;i++){
ll x,y;
scanf("%lld%lld",&x,&y);
mp[max(x,y)].push_back(PLL(x,y));
}
PLL left(0,0),right(0,0);
ll dl=0,dr=0;
for(auto &pr: mp){
sort(pr.second.begin(),pr.second.end(), [](PLL a,PLL b){return make_pair(a.first,-a.second) < make_pair(b.first,-b.second);} );
PLL nl=*pr.second.begin();
PLL nr=pr.second.back();
ll dd=dis(nl,nr);

ll ndl=min(dl+dis(left,nr)+dd,dr+dis(right,nr)+dd);
ll ndr=min(dl+dis(left,nl)+dd,dr+dis(right,nl)+dd);

dl=ndl;
dr=ndr;
left=nl;
right=nr;

}
printf("%lld\n",min(dl,dr));
return 0;
}
23 changes: 23 additions & 0 deletions 1073D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,T;
long long a[200010],dc=0,ans=0;
cin>>n>>T;
for(int i=0; i<(int)n; i++) cin>>a[i];
while(T>0){
long long Tp=T,cn=0;
for(int i=0; i<n; i++){
if(Tp>=a[i]){
Tp-=a[i];
cn++;
}
}
if(cn==0) break;
Tp=T-Tp;
long long mv=T/Tp;
ans+=mv*cn;
T-=mv*Tp;
}
cout<<ans;
}