sabbir_alam

Divisibility Codeforces

Sep 11th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.76 KB | None | 0 0
  1. #include<iostream>
  2. #include<sstream>
  3. #include<string>
  4. #include<cstdlib>
  5. #include<vector>
  6. #include<map>
  7. #include<queue>
  8. #include<stack>
  9. #include<cmath>
  10. #include<cctype>
  11. #include<set>
  12. #include<bitset>
  13. #include<algorithm>
  14. #include<list>
  15.  
  16. #include<stdio.h>
  17. #include<string.h>
  18. #include<stdlib.h>
  19. #include<math.h>
  20. #include<ctype.h>
  21.  
  22. using namespace std;
  23. #define print1(a)    cout<<a<<endl
  24. #define print2(a,b) cout<<a<<" "<<b<<endl
  25. #define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
  26. #define oo          (1<<30)
  27. #define PI          3.141592653589793
  28. #define pi          (2.0*acos(0.0))
  29. #define ERR         1e-5
  30. #define PRE         1e-8
  31. #define SZ(s)       ((int)s.size())
  32. #define LL          long long
  33. #define ISS         istringstream
  34. #define OSS         ostringstream
  35. #define VS          vector<string>
  36. #define VI          vector<int>
  37. #define VD          vector<double>
  38. #define VLL         vector<long long>
  39. #define SII         set<int>::iterator
  40. #define SI          set<int>
  41. #define mem(a,b)    memset(a,b,sizeof(a))
  42. #define fr(i,a,b)   for(i=a;i<=b;i++)
  43. #define frn(i,a,b)  for(i=a;i>=b;i--)
  44. #define fri(a,b)    for(i=a;i<=b;i++)
  45. #define frin(a,b)   for(i=a;i>=b;i--)
  46. #define frj(a,b)    for(j=a;j<=b;j++)
  47. #define frjn(a,b)   for(j=a;j>=b;j--)
  48. #define frk(a,b)    for(k=a;k<=b;k++)
  49. #define frkn(a,b)   for(k=a;k>=b;k--)
  50. #define frl(a,b)    for(l=a;l<=b;l++)
  51. #define frln(a,b)   for(l=a;l>=b;l--)
  52. #define REP(i,n)    for(i=0;i<n;i++)
  53. #define EQ(a,b)     (fabs(a-b)<ERR)
  54. #define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
  55. #define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
  56. #define sqr(a)      ((a)*(a))
  57. #define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
  58. #define typing(j,b) typeof((b).begin()) j=(b).begin();
  59. #define BE(a)       a.begin(),a.end()
  60. #define rev(a)      reverse(BE(a));
  61. #define sorta(a)    sort(BE(a))
  62. #define pb          push_back
  63. #define popb        pop_back
  64. #define mp          make_pair
  65. #define round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;
  66. #define makeint(n,s)  istringstream(s)>>n
  67. #define inpow(a,x,y) int i; a=x;fri(2,y)  a*=x
  68. #define cntbit(mask) __builtin_popcountll(mask)
  69. //0 based print
  70. #define debug_array(a,n) for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
  71. #define debug_matrix(mat,row,col) for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
  72.  
  73. #define csprnt printf("Case %d: ", ++cas);
  74. #define mod         1000000007
  75. #define eulerconstant 0.5772156649
  76.  
  77. template<class T1> void debug(T1 e){cout<<e<<endl;}
  78. template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
  79. template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
  80. template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
  81. template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
  82. template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
  83. template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
  84. template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
  85. template<class T> void debug(T e[110][110],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}
  86. template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
  87. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  88. bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
  89. bool isUpper(char c){return c>='A' && c<='Z';}
  90. bool isLower(char c){return c>='a' && c<='z';}
  91.  
  92.  
  93. int found=0,n,arr[1000000],kk;
  94.  
  95. void dp(int k,int index)
  96. {
  97.     int temp;
  98.     temp=k%n;
  99.     //printf("temp-->%d k-->%d index-->%d\n",temp,k,index);
  100.     if(found)
  101.     {
  102.         return ;
  103.     }
  104.     else if(index==kk+2)
  105.     {
  106.         return ;
  107.     }
  108.     else if(index==kk+1 && temp==0)
  109.     {
  110.         found=1;
  111.         return ;
  112.     }
  113.     else if(!found)
  114.     {
  115.         dp(temp+arr[index],index+1);
  116.         if(found)
  117.         {
  118.             return ;
  119.         }
  120.         dp(temp-arr[index],index+1);
  121.     }
  122.     return ;
  123. }
  124.  
  125. int main()
  126. {
  127.     int i,j;
  128.     kk=0,n=0;
  129.     mem(arr,0);
  130.     found=0;
  131.     scanf("%d %d",&kk,&n);
  132.     fr(i,1,kk)
  133.     {
  134.         scanf("%d",&arr[i]);
  135.     }
  136.     dp(0,1);
  137.     if(found)
  138.     {
  139.         printf("Divisible\n");
  140.     }
  141.     else
  142.         printf("Not divisible\n");
  143.     return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment