이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
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);
~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |