Submission #340433
Source Code Expand
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(auto (i)=(a);(i)<(b);(i)++)
#define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--)
/*
int dp[3] = {1,0,0};
int N;
int main(void){
cin >> N;
N++;
rep(i, 4, N){
dp[i % 3] += dp[(i + 1) % 3] + dp[(i + 2) % 3];
if (dp[i % 3] >= 10007)dp[i % 3] %= 10007;
}
cout << dp[(--N) % 3] << endl;
}
*/
int bit[20][3][3] = { { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 1, 0 } } };
int tmp[21][3][3] = { { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } } };
int e[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
int N;
void calc(int a[3][3], int b[3][3], int c[3][3]){
rep(i, 0, 3)rep(j, 0, 3){
c[i][j] = 0;
rep(k, 0, 3)c[i][j] += a[i][k] * b[k][j];
c[i][j] %= 10007;
}
}
void init(){
rep(i, 1, 20){
calc(bit[i - 1], bit[i - 1], bit[i]);
}
}
int main(void){
init();
cin >> N;
switch (N){
case 1:
case 2:
case 3:cout << tmp[0][0][3 - N] << endl; break;
default:N -= 3;
rep(i, 0, 20){
if ((N >> i) & 1)
calc(tmp[i], bit[i], tmp[i + 1]);
else
calc(tmp[i], e, tmp[i + 1]);
}
/*
rep(i, 0, 3){
rep(j, 0, 3){
printf("%d ", tmp[10][i][j]);
}
cout << endl;
}
*/
cout << tmp[20][0][0] << endl;
break;
}
}
Submission Info
Submission Time |
|
Task |
B - トリボナッチ数列 |
User |
btk15049 |
Language |
C++11 (GCC 4.8.1) |
Score |
100 |
Code Size |
1284 Byte |
Status |
AC |
Exec Time |
35 ms |
Memory |
924 KB |
Judge Result
Set Name |
All |
Score / Max Score |
100 / 100 |
Status |
|
Set Name |
Test Cases |
All |
test_1.txt, test_1000000.txt, test_1002.txt, test_104.txt, test_107843.txt, test_10980.txt, test_1212.txt, test_1238.txt, test_13194.txt, test_14.txt, test_16.txt, test_2.txt, test_210782.txt, test_21694.txt, test_243.txt, test_24916.txt, test_278.txt, test_3.txt, test_31.txt, test_32.txt, test_42.txt, test_5555.txt, test_567914.txt, test_61868.txt, test_765671.txt, test_8195.txt, test_8353.txt, test_9.txt, test_9625.txt, test_97.txt, test_998.txt, test_999998.txt, test_999999.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
24 ms |
672 KB |
sample_02.txt |
AC |
22 ms |
676 KB |
sample_03.txt |
AC |
23 ms |
672 KB |
test_1.txt |
AC |
24 ms |
796 KB |
test_1000000.txt |
AC |
22 ms |
796 KB |
test_1002.txt |
AC |
23 ms |
668 KB |
test_104.txt |
AC |
22 ms |
800 KB |
test_107843.txt |
AC |
22 ms |
796 KB |
test_10980.txt |
AC |
24 ms |
916 KB |
test_1212.txt |
AC |
24 ms |
796 KB |
test_1238.txt |
AC |
24 ms |
800 KB |
test_13194.txt |
AC |
35 ms |
796 KB |
test_14.txt |
AC |
24 ms |
800 KB |
test_16.txt |
AC |
24 ms |
676 KB |
test_2.txt |
AC |
23 ms |
924 KB |
test_210782.txt |
AC |
24 ms |
800 KB |
test_21694.txt |
AC |
24 ms |
800 KB |
test_243.txt |
AC |
23 ms |
920 KB |
test_24916.txt |
AC |
24 ms |
672 KB |
test_278.txt |
AC |
23 ms |
804 KB |
test_3.txt |
AC |
25 ms |
792 KB |
test_31.txt |
AC |
25 ms |
804 KB |
test_32.txt |
AC |
23 ms |
800 KB |
test_42.txt |
AC |
24 ms |
796 KB |
test_5555.txt |
AC |
28 ms |
792 KB |
test_567914.txt |
AC |
24 ms |
672 KB |
test_61868.txt |
AC |
23 ms |
800 KB |
test_765671.txt |
AC |
25 ms |
920 KB |
test_8195.txt |
AC |
25 ms |
796 KB |
test_8353.txt |
AC |
25 ms |
800 KB |
test_9.txt |
AC |
26 ms |
736 KB |
test_9625.txt |
AC |
24 ms |
796 KB |
test_97.txt |
AC |
24 ms |
800 KB |
test_998.txt |
AC |
24 ms |
796 KB |
test_999998.txt |
AC |
23 ms |
796 KB |
test_999999.txt |
AC |
23 ms |
744 KB |