Advertisement
a53

protection1

a53
Jul 19th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int nr, N, code[4][4], dp[100][15][15], old[15], cnt[15];
  6. const int mod = 1000003;
  7.  
  8. bool maxD1 (int i, int j)
  9. {
  10. return (-1 <= i - j && i - j <= 1);
  11. }
  12.  
  13. int main ()
  14. {
  15. freopen ("protection.in", "r", stdin);
  16. freopen ("protection.out", "w", stdout);
  17.  
  18. scanf ("%d", &N), N --;
  19. for (int i=0; i<3; i++)
  20. for (int j=0; j<3; j++)
  21. code[i][j] = ++nr;
  22. for (int i=0; i<3; i++)
  23. for (int j=0; j<3; j++)
  24. for (int k=0; k<3; k++)
  25. for (int p=0; p<3; p++)
  26. if (maxD1 (i, k) && maxD1 (j, p) && (i != k || j != p))
  27. dp[0][code[i][j]][code[k][p]] ++;
  28. for (int i=1; (1LL << i) <= N; i++)
  29. for (int j=1; j<=9; j++)
  30. for (int k=1; k<=9; k++)
  31. for (int p=1; p<=9; p++)
  32. dp[i][j][p] = ((long long) dp[i][j][p] + 1LL * dp[i - 1][j][k] * dp[i - 1][k][p]) % mod;
  33. for (int i=1; i<=9; i++)
  34. cnt[i] = 1;
  35. for (int i=0; (1LL << i) <= N; i++)
  36. if (N & (1LL << i))
  37. {
  38. memcpy (old, cnt, sizeof (cnt));
  39. memset (cnt, 0, sizeof (cnt));
  40. for (int j=1; j<=9; j++)
  41. for (int k=1; k<=9; k++)
  42. cnt[k] = ((long long) cnt[k] + 1LL * old[j] * dp[i][j][k]) % mod;
  43. }
  44. int ans = 0;
  45. for (int i=1; i<=9; i++)
  46. {
  47. ans += cnt[i];
  48. if (ans >= mod) ans -= mod;
  49. }
  50. printf ("%d\n", ans);
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement