結果

問題 No.314 ケンケンパ
ユーザー ignis_fatuusignis_fatuus
提出日時 2015-12-17 07:08:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 917 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 62,020 KB
実行使用メモリ 50,304 KB
最終ジャッジ日時 2023-10-14 12:18:44
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
26,440 KB
testcase_02 AC 8 ms
26,612 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 9 ms
26,412 KB
testcase_07 AC 7 ms
26,464 KB
testcase_08 AC 8 ms
26,464 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    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);
    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);
    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) << endl;
}
0