Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. int main() {
  5.     long long int N;
  6.     long long int S[4][4], n, l; //Should be S[10^9][4], but we only need the last 3 lines!
  7.     scanf("%lld", &N);
  8.    
  9.     const int cur = 0, p1=1, p2=2, p3=3;
  10.     for(l=0;l<=3;l++) S[p1][l] = 1;
  11.  
  12.     for(n=1;n<=N;n++) {
  13.         for(l=1;l<=3;l++) {
  14.             S[cur][l] =  (
  15.                         ((l>=1 && n>=1)?S[p1][1]:0) +
  16.                         ((l>=2 && n>=2)?S[p2][2]:0) +
  17.                         ((l>=3 && n>=3)?S[p3][3]:0)
  18.                         ) % 100000;
  19.         }
  20.  
  21.         if(n==N) continue;
  22.  
  23.         memcpy(S[p3], S[p2], 4*sizeof(long long int));
  24.         memcpy(S[p2], S[p1], 4*sizeof(long long int));
  25.         memcpy(S[p1], S[cur], 4*sizeof(long long int));
  26.         memset(S[cur], 0, 4*sizeof(long long int));
  27.     }
  28.  
  29.     printf("%lld\n", S[cur][3]);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement