Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace __gnu_pbds;
  4. using namespace std;
  5.  
  6.  
  7. #define gc getchar unlocked
  8. #ifndef ONLINE JUDGE
  9. #define gc getchar
  10. #endif // ONLINE JUDGE
  11.  
  12. #define pc putchar_unlocked
  13. #ifndef ONLINE JUDGE
  14. #define pc putchar
  15. #endif // ONLINE JUDGE
  16.  
  17. #define fRead freopen("input.txt","r",stdin)
  18. #define fWrite freopen ("output.txt","w",stdout)
  19.  
  20. #define eps 1e-8
  21. #define inf 0x3f3f3f3f
  22. #define INF 2e18
  23. #define LL long long
  24. #define ULL unsigned long long
  25. #define PI acos(-1.0)
  26. #define pb push_back
  27. #define mk make_pair
  28. #define pii pair<int,int>
  29. #define pLL pair<LL,LL>
  30. #define ff first
  31. #define ss second
  32. #define all(a) a.begin(),a.end()
  33. #define rall(a) a.rbegin(),a.rend()
  34. #define SQR(a) ((a)*(a))
  35. #define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
  36. #define min3(a,b,c) min(a,min(b,c))
  37. #define max3(a,b,c) max(a,max(b,c))
  38. #define min4(a,b,c,d) min(min(a,b),min(c,d))
  39. #define max4(a,b,c,d) max(max(a,b),max(c,d))
  40. #define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
  41. #define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
  42. #define Iterator(a) __typeof__(a.begin())
  43. #define rIterator(a) __typeof__(a.rbegin())
  44. #define FOR(a,it) for(Iterator(a) it = a.begin();it != a.end(); it++)
  45. #define rFOR(a,it) for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
  46. #define FastRead ios_base::sync_with_stdio(0);cin.tie(0)
  47. #define CasePrint pc('C'); pc('a'); pc('s'); pc('e'); pc(' '); write(qq++,false); pc(':'); pc(' ')
  48. #define vi vector <int>
  49. #define vL vector <LL>
  50. #define For(I,A,B) for(int I = (A); I < (B); ++I)
  51. #define rFor(I,A,B) for(int I = (A); I >= (B); --I)
  52. #define Rep(I,N) For(I,0,N)
  53. #define REP(I,N) For(I, 1, N + 1)
  54. #define gti int, vi, greater<int>
  55. #define gtL LL, vL, greater<LL>
  56.  
  57. const int MOD = 1e9 + 7;
  58. int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
  59. int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
  60. template <typename T> using orderset = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
  61. template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b); if(a < b) swap(a, b); while ( b ) { a = a % b; swap ( a, b ); } return a;}
  62. template <typename T> inline T EGCD(T a,T b,T &x,T &y){if(a == 0) {x = 0;y = 1;return b;}T x1, y1;T d = EGCD(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
  63. template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
  64. template <typename T> inline T BigMod(T A,T B,T M = MOD){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
  65. template <typename T> inline T InvMod (T A,T M = MOD){return BigMod(A,M-2,M);}
  66. /*---------------------------fast I/O------------------------------------*/
  67. #define scani2(a,b) scani(a) , scani(b)
  68. #define scani3(a,b,c) scani(a), scani(b), scani(c)
  69. #define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
  70. #define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
  71. template <typename T> T scani(T &n){n = 0;bool negative = false;char c = gc();while( c < '0' || c > '9'){if(c == '-') negative = true;c = gc();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = gc();}if(negative) n = ~(n-1);return n;}
  72. template <typename T> void write(T n,int type = true){if(n<0) {pc('-');n = -n;}if(!n) {pc('0');if(type==32) pc(' '); else if(type) pc('\n'); return;}char buff[22];int len = 0;while(n) buff[len++] = n%10+48,n/=10;for(int i=len-1;i>=0;i--) pc(buff[i]);if(type==32) pc(' '); else if(type) pc('\n');}
  73. int scans(char *a){int i=0;char c = 0;while(c < 33) c = gc();while(c > 33){a[i++] = c;c = gc();}a[i] = 0;return i;}
  74. /*********************************************** End of template *********************************************/
  75. const int N = 200005;
  76. const int M = 250;
  77.  
  78. int cnt[22];
  79. int dp[22][22222 * 6];
  80. int vs[22][22222 * 6], visId;
  81.  
  82. bool ans_me(int id, int rem)
  83. {
  84. if(rem < 0) return 0;
  85. if(rem == 0) return 1;
  86. if(id > 6) return 0;
  87. if(vs[id][rem] == visId) return dp[id][rem];
  88. vs[id][rem] = visId;
  89. bool ret = false;
  90. for(int i=0;i<=cnt[id];i++){
  91. ret |= ans_me(id + 1, rem - id * i);
  92. if(ret) break;
  93. }
  94. return dp[id][rem] = ret;
  95. }
  96.  
  97. int main()
  98. {
  99. int qq = 1;
  100. while(true){
  101. for(int i=1;i<=6;i++) scani(cnt[i]);
  102. int sum = 0;
  103. for(int i=1;i<=6;i++) sum += i * cnt[i];
  104. if(!sum) break;
  105. printf("Collection #%d:\n", qq++);
  106. if(sum & 1){
  107. puts("Can't be divided.\n");
  108. continue;
  109. }
  110. sum /= 2;
  111. visId++;
  112. if(ans_me(1, sum)) puts("Can be divided.\n");
  113. else puts("Can't be divided.\n");
  114. }
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement