Codeforces Round #420 (Div. 2), problem: (E) Okabe and El Psy Kongroo Solution In C/C++

By |2017-08-06T21:27:27+00:00August 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , |

#include <stdio.h> #define m 1000000007u typedef long long unsigned llu; typedef unsigned u; u M[16][64][16][16]; u X[16],Y[16],*A,*B,*C; int main() { u q,n,e,i,j,k; for(n=-1;++n<16;) { for(i=-1;++i<=n;) for(j=-1;++j<=n;) M[n][0][i][j]=(i<j?j-i:i-j)<2; for(e=0;++e<64;) { for(i=-1;++i<=n;) for(j=-1;++j<=n;) for(k=-1;++k<=n;) M[n][e][i][j]= ( M[n][e][i][j]+ M[n][e-1][i][k]* (llu)M[n][e-1][k][j] )%m; } } llu x,y,z;*(A=X)=1;B=Y; for(scanf("%u%I64u",&q,&z);q--;) { [...]

Codeforces Round #420 (Div. 2), problem: (D) Okabe and City Solution In C/C++

By |2017-08-06T21:25:24+00:00August 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<cmath> using namespace std; const int maxn=1e4+5; const int inf=0x7f7f7f7f; int x[maxn],y[maxn],dis[maxn]; bool vis[maxn]; int k,n,m; int bfs() { queue<int>q; q.push(1); //memset //for(int i=1;i<=n;i++)dis[i]=inf; memset(dis,0x7f,sizeof dis); dis[1]=0; vis[1]=true; while(!q.empty()) { int u; u=q.front();q.pop(); for(int i=1;i<=k;i++) { if(u==i)continue; int w=inf; int [...]

Codeforces Round #420 (Div. 2), problem: (C) Okabe and Boxes Solution In C/C++

By |2017-08-06T21:21:34+00:00August 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include <cstdio> using namespace std; int n,s[300005],top; int main() { int i,j,ans=0; char op[15]; scanf("%d",&n); for(i=j=1;i<=2*n;++i) { scanf("%s",op); if(op[0]=='a') scanf("%d",&s[++top]); else { if(top) { if(s[top]==j) --top; else top=0,++ans; } ++ j; } } printf("%d\n",ans); }

Codeforces Round #420 (Div. 2), problem: (B) Okabe and Banana Trees Solution In C/C++

By |2017-08-06T21:19:00+00:00August 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , |

#include <iostream> using namespace std; int main(){ long long int m,b,s=0,x; cin>>m>>b; for(int i=0;i<=b;i++){ x=(b-i)*m; s=max(s,((i+1)*(x+1)*(i+x))/2); } cout<<s; }

Codeforces Round #420 (Div. 2), problem: (A) Okabe and Future Gadget Laboratory Solution In C/C++

By |2017-08-06T21:15:36+00:00August 6th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include <bits/stdc++.h> using namespace std; int main() { int n,a[55][55],i,j,k,l,f; cin>>n; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>a[i][j]; for(i=0;i<n;i++) for(j=0;j<n;j++) { f=0; for(k=0;k<n;k++) for(l=0;l<n;l++) if(a[i][j]==a[i][k]+a[l][j]||a[i][j]==1) f=1; if(!f) { cout<<"No\n"; return 0; } } cout<<"Yes\n"; return 0; }