Codeforces Round #407 (Div. 2), problem: (E) The Great Mixing Solution in C

By | 2017-04-09T01:36:04+00:00 April 9th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<bits/stdc++.h> using namespace std; int n,k,f[1005]; bitset<2001> dp[2]; int main() { cin>>n>>k; for(int i=1,t;i<=k;i++) { scanf("%d",&t); f[t]=1; } dp[0][1000]=1; int now=0; for(int i=1;i<=1000;i++) { now^=1; dp[now].reset(); for(int j=0;j<=1000;j++) if(f[j])dp[now]|=(dp[now^1]<<j)>>n; if(dp[now][1000]) { return 0*printf("%d\n",i); } } puts("-1"); return 0; }

Codeforces Round #407 (Div. 2), problem: (D) Weird journey Solution in C

By | 2017-04-09T01:29:16+00:00 April 9th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include<bits/stdc++.h> #define ll long long using namespace std; ll in[1000001]; vector<int>adj[1000001]; ll ans=0; bool g[1000001]; int dfs(int cur) { g[cur]=true; int k,cnt=1; for(k=0;k<adj[cur].size();k++) { if(g[adj[cur][k]]==false) { cnt+=dfs(adj[cur][k]); } } return cnt; }; ll ct[1000001]; int main() { int n,m,i,u,v; cin>>n>>m; for(i=0;i<m;i++) { scanf("%d%d",&u,&v); if(u==v) [...]

Codeforces Round #407 (Div. 2), problem: (B) Masha and geometric depression Solution in C

By | 2017-04-09T01:08:51+00:00 April 9th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#include <iostream> #include <map> using namespace std; map<long long, int> was; map<long long, int> bad; int main() { long long b, q, l, m; cin >> b >> q >> l >> m; for(int i = 0; i < m; i++) { long long [...]

Codeforces Round #407 (Div. 2), problem: (A) Anastasia and pebbles Solution in C

By | 2017-04-09T01:00:33+00:00 April 9th, 2017|Categories: C/C++, Programming|Tags: , , |

#include<stdio.h> int main() { int n,k; scanf("%d%d",&n,&k); int a,i,m=0; for(i=0;i<n;i++) { scanf("%d",&a); if(a%k==0) m+=a/k; else m+=a/k+1; } printf("%d",(m+1)/2); return 0; }