답안 #71721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71721 2018-08-25T13:28:33 Z 유애나(#2242, kdh9949) 십자가 놓기 (FXCUP3_cross) C++
100 / 100
3 ms 724 KB
#include <bits/stdc++.h>
using namespace std;

const int M = int(1e9) + 7;

struct Mat{
    int a[9][9];
    Mat operator*(const Mat &o) const {
        Mat r;
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                r.a[i][j] = 0;
                for(int k = 0; k < 9; k++)
                    r.a[i][j] = (r.a[i][j] + 1LL * a[i][k] * o.a[k][j]) % M;
            }
        }
        return r;
    }
} a;

Mat p(Mat x, int k){
    if(k == 1) return x;
    if(k & 1) return p(x * x, k / 2) * x;
    return p(x * x, k / 2);
}

int n, r;
int t[9][9] = {
    {1, 0, 0, 0, 1, 0, 1, 1, 0},
    {1, 0, 0, 0, 0, 0, 1, 1, 0},
    {1, 0, 0, 0, 1, 0, 0, 1, 0},
    {1, 0, 0, 0, 1, 0, 1, 0, 0},
    {0, 1, 0, 0, 0, 0, 0, 0, 1},
    {0, 1, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 0, 1, 0, 0, 0},
    {0, 0, 0, 1, 0, 0, 0, 0, 0}
};

int main(){
    scanf("%d", &n);
    if(n == 3){ puts("4"); return 0; }
    for(int i = 0; i < 9; i++) for(int j = 0; j < 9; j++) a.a[i][j] = t[i][j];
    a = p(a, n - 3);
    for(int i = 0; i < 9; i++) for(int j = 0; j < 4; j++) r = (r + a.a[i][j]) % M;
    printf("%d\n", r);
}

Compilation message

cross.cpp: In function 'int main()':
cross.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 3 ms 564 KB Output is correct
10 Correct 2 ms 564 KB Output is correct
11 Correct 3 ms 564 KB Output is correct
12 Correct 2 ms 564 KB Output is correct
13 Correct 2 ms 564 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 3 ms 564 KB Output is correct
10 Correct 2 ms 564 KB Output is correct
11 Correct 3 ms 564 KB Output is correct
12 Correct 2 ms 564 KB Output is correct
13 Correct 2 ms 564 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct