結果

問題 No.314 ケンケンパ
ユーザー ignis_fatuus
提出日時 2015-12-17 07:23:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 51 ms / 1,000 ms
コード長 966 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 62,244 KB
実行使用メモリ 57,916 KB
最終ジャッジ日時 2024-09-16 07:09:12
合計ジャッジ時間 1,566 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0