Advertisement
Guest User

Save The Land

a guest
Mar 5th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <complex>
  13. #include <utility>
  14. #include <fstream>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <cctype>
  19. #include <cstdio>
  20. #include <cmath>
  21. #include <cstdlib>
  22. #include <ctime>
  23. #include <cstring>
  24. #include <climits>
  25.  
  26. using namespace std;
  27.  
  28.  
  29. typedef long long LL;
  30. typedef unsigned long long ULL;
  31. typedef long double LD;
  32. typedef vector<int> VI;
  33. typedef vector<string> VS;
  34. typedef vector<VI> VVI;
  35. typedef pair<int,int> PII;
  36.  
  37. #define REP(i,a,b) for(int i=a;i<b;i++)
  38. #define rep(i,n) REP(i,0,n)
  39. #define REV(i,a,b) for(int i=a-1;i>=b;i--)
  40. #define rev(i,n) REV(i,n,0)
  41. #define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
  42. #define GI ({ int x; scanf("%d",&x); x; })
  43. #define GLL ({ LL x; scanf("%lld",&x); x; })
  44. #define ALL(v) v.begin(),v.end()
  45. #define PB push_back
  46. #define MP make_pair
  47. #define PQ priority_queue
  48. #define inf (int)(1e9)
  49. #define linf (LL)(1e18)
  50. #define eps (double)(1e-9)
  51. #define leps (LD)(1e-18)
  52. #define PI (double)(3.141592653589793238)
  53. #define MOD 1000000007
  54.  
  55.  
  56. void mult(LL a[4][4],LL b[4][4])
  57. {
  58.     LL c[4][4];
  59.     rep(i,4)
  60.         rep(j,4)
  61.         {
  62.             c[i][j]=0LL;
  63.             rep(k,4)
  64.                 c[i][j]=(c[i][j]+a[i][k]*b[k][j])%MOD;
  65.         }
  66.     rep(i,4)
  67.         rep(j,4)
  68.             a[i][j]=c[i][j];
  69. }
  70.  
  71. LL solve(LL a[4][4],LL b)
  72. {
  73.     b-=3;
  74.     LL ans[4][4]={{1LL,0LL,0LL,0LL},{0LL,1LL,0LL,0LL},{0LL,0LL,1LL,0LL},{0LL,0LL,0LL,1LL}};
  75.     while(b)
  76.     {
  77.         if(b&1)
  78.             mult(ans,a);
  79.         b>>=1;
  80.         mult(a,a);
  81.     }
  82.     return (3*(ans[0][0]+ans[2][0]+3*ans[3][0])+(ans[0][1]+ans[2][1]+3*ans[3][1])+2*(ans[0][3]+ans[2][3]+3*ans[3][3]))%MOD;
  83. }
  84.  
  85. int main()
  86. {
  87.     //freopen("input.txt","r",stdin);
  88.     //freopen("output.txt","w",stdout);
  89.     LL n;
  90.     cin>>n;
  91.     LL a[4][4]={{0LL,2LL,1LL,3LL},{1LL,0LL,0LL,0LL},{0LL,1LL,0LL,0LL},{0LL,0LL,0LL,2LL}};
  92.     cout<<solve(a,n-1)<<'\n';
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement