Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (F) Bamboo Partition Solution In C/C++

By |2017-07-24T17:50:48+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , , , |

#include<cstdio> #include<algorithm> using namespace std; int n,a[110]; long long k,ans=0; int main(){ scanf("%d%lld",&n,&k); for (int i=1; i<=n; i++) scanf("%d",&a[i]); for (long long l=1,r; l<=1LL<<62; l=r+1){ // printf("%lld %lld\n",l,r); long long cnt=0,weight=0; r=1LL<<62; for (int i=1; i<=n; i++){ cnt+=(((a[i]-1)/l)+1)*l-a[i]; weight+=(a[i]-1)/l+1; if ((a[i]>l) && ((a[i]-1)/((a[i]-1)/l) < [...]

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (E) Cards Sorting Solution in C/C++

By |2017-07-24T17:48:33+00:00July 24th, 2017|Categories: Uncategorized|

#include <bits/stdc++.h> using namespace std; set<int> s[100005]; int main() { int n,i,x; cin>>n; int m=0; for(i=0;i<n;i++) { cin>>x; s[x].insert(i); m=max(m,x); } i=0; long long int c=0,val=1,ans=0; while(i<=m) { if(s[i].size()==0) i++; else { set<int>::iterator itr=s[i].lower_bound(c); if(itr!=s[i].end()) { c=*itr; ans+=val; s[i].erase(itr); } else { c=0; val++; [...]

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (B) Keyboard Layouts Solution In C/C++

By |2017-07-24T17:44:05+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , , , |

#include <bits/stdc++.h> using namespace std; string s1, s2, t; int main() { cin >> s1 >> s2 >> t; for(char c : t) putchar(c < 58 ? c : s2[s1.find(c < 91 ? c + 32 : c)] - (c < 91 ? 32 [...]

Codeforces Round #416 (Div. 2), problem: (E) Vladik and Entertaining Flags Solution In C/C++

By |2017-07-24T17:24:20+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include<set> #include<map> #include<cmath> #include<queue> #include<cctype> #include<vector> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define Rep(i,x,y) for(int i=x;i<y;++i) #define For(i,x,y) for(int i=x;i<=y;++i) #define Forn(i,x,y) for(int i=x;i>=y;--i) const int N = 1e5+5; typedef [...]

Codeforces Round #416 (Div. 2), problem: (C) Vladik and Memorable Trip Solution In C/C++

By |2017-07-24T17:21:24+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<cstdio> using namespace std; int main(){ int n,a[5005],c[5005],f[5005]; scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",a+i),c[a[i]]++; for(int i=0;i<n;i++){ int v[5005]={0},temp=0,xo=0; for(int j=i;j>=0;j--){ if(v[a[j]]==0)v[a[j]]=1,temp+=c[a[j]],xo^=a[j]; f[i+1]=max(f[i+1],f[j]+(--temp?0:xo)); } } printf("%d",f[n]); return 0; }

Codeforces Round #415 (Div. 2), problem: (C) Do you want a date? Solution In C/C++

By |2017-07-24T16:54:19+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include <bits/stdc++.h> using namespace std; long long n,a[300007],r[300007],m=1e9+7,sum=0; int main(){ std::cin >> n;r[0] = 1; for(int i = 0;i<n;i++)cin>>a[i],r[i+1]=(r[i]*2)%m; sort(a,a+n); for(int i=0;i<n;i++) sum+=(a[i]*(r[i]-r[n-i-1]))%m,sum%=m; cout << sum%m; }

Codeforces Round #415 (Div. 2), problem: (B) Summer sell-off Solution In C/C++

By |2017-07-24T16:52:53+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include<bits/stdc++.h> using namespace std; int64_t n,f,k,l,i,w,s,a[100179]; int main(){ for(cin>>n>>f;i<n;i++)cin>>k>>l,w=min(k,l),a[i]=min(2*k,l)-w,s+=w; sort(a,a+n); for(i=0;i<n;i++)s+=i<f?a[n-1-i]:0; cout<<s; }

Tinkoff Challenge – Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2), problem: (D) Labelling Cities Solution In C/C++

By |2017-07-24T16:39:18+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , , , |

#include<bits/stdc++.h> #define MAXN 300100 using namespace std; struct node{int y,next;}e[MAXN<<1]; int n,m,len,Link[MAXN],p[MAXN],hash[MAXN],col[MAXN],vis[MAXN],used[MAXN<<1]; inline int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();} return x*f; } void insert(int x,int y){e[++len].next=Link[x];Link[x]=len;e[len].y=y;} void dfs(int x){ vis[x]=1; for(int i=Link[x];i;i=e[i].next)if(hash[e[i].y]==hash[x])col[e[i].y]=col[x]; for(int i=Link[x];i;i=e[i].next)if(!vis[e[i].y]){ if(!col[e[i].y]){ for(int j=col[x]-1;j<=col[x]+1;++j)if(!used[j]){ [...]

Codeforces Round #411 (Div. 2), problem: (B) 3-palindrome Solution In C/C++

By |2017-07-24T01:55:33+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include <cstdio> int n; int main (){ scanf("%d", &n); for (int i = 0; i < n; i++) printf("%c", i % 4 < 2 ? 'a' : 'b'); printf("\n"); return 0; }

Codeforces Round #410 (Div. 2), problem: (B) Mike and strings Solution In C/C++

By |2017-07-24T01:45:48+00:00July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include <bits/stdc++.h> using namespace std; string s[51]; int main() { int n, t, ans; ans = INT_MAX; cin>>n; string temp; for(int i=0; i<n; i++) cin>>s[i]; for(int i=0; i<n; i++) { t = 0; for(int j=0; j<n; j++) { temp=s[j]+s[j]; if(temp.find(s[i])==string::npos) { cout<<-1<<endl; return 0; [...]