Codeforces Round #473 (Div. 2), problem: (F) Mahmoud and Ehab and yet another xor task Solution In C/C++

By | 2018-04-18T13:41:56+00:00 April 18th, 2018|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<bits/stdc++.h> #define LL long long using namespace std; const int maxn = 1e5+5; const int mod =1e9+7; typedef pair<int,int>pii; int a[maxn]; int b[25]; int ans[maxn]; int p[maxn]; vector<pii>q[maxn]; int main() { int n,m; cin>>n>>m; memset(b,-1,sizeof(b)); p[0]=1; for(int i=1;i<=n;i++)scanf("%d",&a[i]),p[i]=p[i-1]*2%mod; for(int i=1;i<=m;i++) { int l,x; scanf("%d%d",&l,&x); [...]

Codeforces Round #473 (Div. 2), problem: (B) Mahmoud and Ehab and the message Solution In C/C++

By | 2018-04-18T13:14:02+00:00 April 18th, 2018|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<bits/stdc++.h> using namespace std; map<string,int> ms; string str; int arr[100005],temp[100005],mn[100005]; int main() { int n,k,m;cin>>n>>k>>m; for(int i=1;i<=n;i++)cin>>str,ms[str]=i; for(int i=1;i<=n;i++)cin>>arr[i],mn[i]=1e9+7; for(int i=1,j;i<=k;i++) { int x;cin>>x; while(x--)cin>>j,temp[j]=i,mn[i]=min(mn[i],arr[j]); } unsigned long long res=0; while(cin>>str){res+=mn[temp[ms[str]]];} return cout<<res<<"\n",0; }

Codeforces Round #473 (Div. 2), problem: (A) Mahmoud and Ehab and the even-odd game Solution In C/C++

By | 2018-04-18T13:09:29+00:00 April 18th, 2018|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include <stdio.h> int main() { int N; scanf("%d", &N), puts(N&1 ? "Ehab" : "Mahmoud"); }

Codeforces Round #443 (Div. 2), problem: (E) Tournament Solution In C/C++

By | 2017-11-08T09:27:59+00:00 November 8th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<cstdio> #include<cstring> #include<algorithm> #include<set> using namespace std; int n,k; struct node { int maxx[15],minn[15],sz; node() { int x;sz = 1; for(int i = 1; i <= k ; i ++) { scanf("%d",&x); minn[i] = maxx[i] = x; } } bool operator<(const node &nd)const { [...]

Codeforces Round #443 (Div. 2), problem: (D) Teams Formation Solution In C/C++

By | 2017-11-08T09:26:00+00:00 November 8th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include <stdio.h> struct node { __int64 ans,num; }s[101000]; int main() { int n,k,m; while(~scanf("%d%d%d",&n,&k,&m)) { scanf("%I64d",&s[0].num); s[0].ans=1; int len=1; for(int i=1;i<n;i++) { int x; scanf("%d",&x); if(x==s[len-1].num) { s[len-1].ans++; if(s[len-1].ans==k) { s[len-1].ans=0; len--; } } else { s[len].num=x; s[len].ans=1; len++; } } int l=0,r=len-1; __int64 [...]

Codeforces Round #443 (Div. 2), problem: (C) Short Program Solution In C/C++

By | 2017-11-08T09:24:01+00:00 November 8th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include <iostream> using namespace std; const int maxn = 5e5; int n, x, a = 0, b = 1023, y[3]; char c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c >> x; if [...]

Codeforces Round #443 (Div. 2), problem: (A) Borya’s Diagnosis Solution In C/C++

By | 2017-11-08T09:19:12+00:00 November 8th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<bits/stdc++.h> using namespace std; int main() { int n,i,s,d,t=0; cin>>n; for(i=0;i<n;i++) { cin>>s>>d; while(s<=t) { s=s+d; } t=s; } cout<<s<<endl; }

Codeforces Round #444 (Div. 2), problem: (F) Row of Models Solution In C/C++

By | 2017-11-07T20:11:01+00:00 November 7th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<bits/stdc++.h> #define maxn 1000050 using namespace std; int a[maxn],b[maxn],c[maxn],n,k,m,t; int main() { scanf("%d%d",&n,&k); for (int i=0;i<n;i++) scanf("%d",&a[i]); a[n]=0; memset(c,-1,sizeof(c)); m=0;b[m]=0;c[0]=0;t=0; for (int i=1;i<=n;i++) if (a[i]<a[b[m]]) b[++m]=i,c[i]=m; for (int i=1;i<=m;i++) if (b[i]-b[i-1]>2*k) {puts("NO");return 0;} else if (b[i]-b[i-1]>k) { if (t) {puts("NO");return 0;} else t=i; } [...]

Codeforces Round #444 (Div. 2), problem: (B) Cubes for Masha Solution In C/C++

By | 2017-11-07T20:00:13+00:00 November 7th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<stdio.h> int main() { int n,i,j,k,m,A[10][10],B[1000]; scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=6;j++){ scanf("%d",&A[i][j]);} } for(i=1;i<=100;i++){ B[i]=0;} for(i=1;i<=n;i++){ for(j=1;j<=6;j++){ B[A[i][j]]=1; for(k=1;k<=n;k++){ for(m=1;m<=6;m++){ if (k!=i){ B[A[i][j]*10+A[k][m]]=1; } } } } } i=1; while(B[i]){ i++;} printf("%d",i-1); return 0; }

Codeforces Round #436 (Div. 2), problem: (F) Cities Excursions Solution In C/C++

By | 2017-09-26T16:42:50+00:00 September 26th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N = 3005, INF = 0x3f3f3f3f; int n, m, q, f[N][12]; bool vis[N]; struct Edge { int to; Edge *next; Edge () {} Edge (int to, Edge *next) : to(to), next(next) {} }*head[N], pool[N << 1], [...]