結果
問題 | No.314 ケンケンパ |
ユーザー | ignis_fatuus |
提出日時 | 2015-12-17 07:23:59 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 49 ms / 1,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 438 ms |
コンパイル使用メモリ | 62,236 KB |
実行使用メモリ | 50,036 KB |
最終ジャッジ日時 | 2023-10-14 12:18:46 |
合計ジャッジ時間 | 1,567 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
49,428 KB |
testcase_01 | AC | 9 ms
26,408 KB |
testcase_02 | AC | 10 ms
26,496 KB |
testcase_03 | AC | 9 ms
26,592 KB |
testcase_04 | AC | 1 ms
4,348 KB |
testcase_05 | AC | 1 ms
4,348 KB |
testcase_06 | AC | 10 ms
26,504 KB |
testcase_07 | AC | 9 ms
26,420 KB |
testcase_08 | AC | 8 ms
26,464 KB |
testcase_09 | AC | 11 ms
26,588 KB |
testcase_10 | AC | 9 ms
26,484 KB |
testcase_11 | AC | 8 ms
26,380 KB |
testcase_12 | AC | 9 ms
26,588 KB |
testcase_13 | AC | 9 ms
26,536 KB |
testcase_14 | AC | 9 ms
26,656 KB |
testcase_15 | AC | 9 ms
26,728 KB |
testcase_16 | AC | 9 ms
26,900 KB |
testcase_17 | AC | 13 ms
28,872 KB |
testcase_18 | AC | 27 ms
37,616 KB |
testcase_19 | AC | 49 ms
50,036 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; using Long=long long; Long saa(Long a); Long sba(Long a); Long sab(Long a); const Long cache_size=1e6; Long saa(Long a) { static vector<Long> cache(cache_size); if(a==2) return 1; if(cache[a]!=0) return cache[a]; const Long b = sba(a-1)%Long(1e9+7); cache[a]=b; return b; } Long sba(Long a) { static vector<Long> cache(cache_size); if(a==2) return 0; if(cache[a]!=0) return cache[a]; const Long b = sab(a-1)%Long(1e9+7); cache[a]=b; return b; } Long sab(Long a) { static vector<Long> cache(cache_size); if(a==2) return 1; if(cache[a]!=0) return cache[a]; const Long b = (sba(a-1) + saa(a-1))%Long(1e9+7); cache[a]=b; return b; } Long s(Long a) { if(a==1) return 1; // a if(a==2) return 2; // ab, aa return sab(a)+saa(a)+sba(a); } int main() { Long n;cin>>n; cout << s(n)%Long(1e9+7) << endl; }