# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62608 | imsifile | Cross on the Grid (FXCUP3_cross) | C++14 | 3 ms | 540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<memory.h>
typedef long long lld;
const lld mod = 1000000007;
struct mat {
lld ba[9][9];
mat operator* (const mat &c){
mat res; memset(res.ba, 0, sizeof(res.ba));
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
for(int k=0; k<9; k++) res.ba[i][j] += ba[i][k]*c.ba[k][j];
res.ba[i][j] %= mod;
}
}
return res;
}
} base, res;
int N;
int main(){
scanf("%d", &N); N-=4;
if(N<0){ puts("4"); return 0; }
memset(base.ba, 0, sizeof(base.ba));
memset(res.ba, 0, sizeof(res.ba));
for(int i=0; i<9; i++) res.ba[i][i] = 1;
base.ba[0][0] = base.ba[0][1] = base.ba[0][2] = base.ba[0][3] = 1;
base.ba[1][4] = base.ba[1][5] = base.ba[2][6] = base.ba[3][7] = base.ba[3][8] = 1;
base.ba[4][0] = base.ba[4][2] = base.ba[4][3] = 1;
base.ba[6][0] = base.ba[6][1] = base.ba[6][3] = 1;
base.ba[7][0] = base.ba[7][1] = base.ba[7][2] = 1;
base.ba[5][7] = base.ba[8][4] = 1;
for(; N; N>>=1){
if(N&1) res = res*base;
base = base*base;
}
lld sum=0;
for(int i=0; i<9; i++){
for(int j=0; j<9; j++) sum += res.ba[i][j];
}
printf("%lld\n", sum%mod);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |