Submission #71813

# Submission time Handle Problem Language Result Execution time Memory
71813 2018-08-25T16:21:19 Z chobo(#2238, andy627) Cross on the Grid (FXCUP3_cross) C++17
100 / 100
4 ms 604 KB
#include <stdio.h>
#include <algorithm>
#define LL long long
#define MOD 1000000007
using namespace std;

struct mat{
    LL x[16][16];

    mat operator*(const mat &p)const{
        mat ret;
        for(int i=0;i<16;i++){
            for(int j=0;j<16;j++){
                ret.x[i][j]=0;
                for(int k=0;k<16;k++) ret.x[i][j]=(ret.x[i][j]+x[i][k]*p.x[k][j])%MOD;
            }
        }
        return ret;
    }
}it;

int dx[]={0,1,0,-1,0};
int dy[]={0,0,1,0,-1};

bool collapse(int a,int b,int y){
    if(!a || !b) return 0;

    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(a+dx[i]!=b+dx[j]) continue;
            if(dy[i]!=y+dy[j]) continue;
            return 1;
        }
    }

    return 0;
}

mat pw(mat x,int p){
    mat ret=it;

    while(p){
        if(p&1) ret=ret*x;
        x=x*x; p>>=1;
    }

    return ret;
}

int main(){
    int n;

    scanf("%d",&n);

    mat x;
    for(int i=0;i<16;i++){
        for(int j=0;j<16;j++){
            x.x[i][j]=0;
            if(i/4==j%4){
                if(collapse(j/4,i%4,2)) continue;
                if(collapse(j%4,i%4,1)) continue;
                x.x[i][j]=1;
            }
        }
    }

    for(int i=0;i<16;i++) it.x[i][i]=1;
    x=pw(x,n-3);

    int ans=0;
    for(int i=0;i<16;i++){
        for(int j=0;j<4;j++) ans=(ans+x.x[i][j])%MOD;
    }

    printf("%d",ans);

    return 0;
}

Compilation message

cross.cpp: In function 'int main()':
cross.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 3 ms 520 KB Output is correct
10 Correct 2 ms 520 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 400 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 3 ms 520 KB Output is correct
10 Correct 2 ms 520 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 4 ms 604 KB Output is correct