Advertisement
a53

divtrei

a53
Feb 28th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /*
  2. Implementare: Dan Pracsiu
  3. */
  4. #include<cstdio>
  5. using namespace std;
  6. int r3[3],N,K;
  7. long xp[3],xc[3];
  8. int main()
  9. {
  10. int i,j,x;
  11. freopen("divtrei.in","r",stdin);
  12. freopen("divtrei.out","w",stdout);
  13. scanf("%d %d",&N,&K);
  14. for (i=0;i<N;i++)
  15. {
  16. scanf("%d",&x);
  17. r3[x%3]++;
  18. }
  19.  
  20. xp[0]=r3[0];xp[1]=r3[1];xp[2]=r3[2];
  21. for (i=1;i<K;i++)
  22. {
  23. if (r3[0] > 0)
  24. {
  25. xc[0] += r3[0]*xp[0];
  26. xc[1] += r3[0]*xp[1];
  27. xc[2] += r3[0]*xp[2];
  28. }
  29. if (r3[1] > 0)
  30. {
  31. xc[0] += r3[1]*xp[2];
  32. xc[1] += r3[1]*xp[0];
  33. xc[2] += r3[1]*xp[1];
  34. }
  35. if (r3[2] > 0)
  36. {
  37. xc[0] += r3[2]*xp[1];
  38. xc[1] += r3[2]*xp[2];
  39. xc[2] += r3[2]*xp[0];
  40. }
  41. for (j=0;j<3;j++)
  42. {
  43. xp[j] = xc[j]%4001;
  44. xc[j] = 0;
  45. }
  46. }
  47. printf("%ld\n",xp[0]);
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement