結果

問題 No.314 ケンケンパ
ユーザー RonlynesRonlynes
提出日時 2017-08-22 14:53:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 751 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 55,956 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 04:44:28
合計ジャッジ時間 999 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int mod = 1e9+7;
int main(void){
    int n;
    cin >> n;
    long long sum = 0;
    long long memo[3];
    if(n == 1){
        cout << "1" << endl;
        return 0;
    }else if(n==2){
        cout << "2" << endl;
        return 0;
    }else if(n==3){
        cout << "2" << endl;
        return 0;
    }
    memo[0]=0; //けんけん
    memo[1]=1; //けんぱ
    memo[2]=1; //ぱけん
    long long tmp1, tmp2, tmp3;
    for(int i=4; i<=n; i++){
        tmp1 = memo[2];
        tmp2 = (memo[0] + memo[2])%mod;
        tmp3 = memo[1];
        memo[0] = tmp1;
        memo[1] = tmp2;
        memo[2] = tmp3;
    }
    sum = (memo[0]+memo[1]+memo[2])%mod;
    cout << sum%mod << endl;
    return 0;
}
0