結果

問題 No.314 ケンケンパ
ユーザー arrowsarrows
提出日時 2017-01-22 00:55:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 1,000 ms
コード長 908 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 65,196 KB
実行使用メモリ 26,920 KB
最終ジャッジ日時 2023-08-24 19:56:09
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>

using namespace std;

constexpr int MOD = ((1e9) + 7);

void add(int& l, int r)
{
    l = (l + r) % MOD;
}

int main()
{
    int N;
    cin >> N;
    
    int dp[N][2][3];
    memset(dp, 0, sizeof(dp));
    
    dp[0][0][1] = 1;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {                           
                add(dp[i][0][k + 1], dp[i - 1][j][k]);
                if (j == 0) {
                    add(dp[i][1][0], dp[i - 1][j][k]);
                }                
            }
            
            if (j == 0) {
                add(dp[i][1][0], dp[i - 1][0][2]);
            }
        }
    }
    
    int res = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            add(res, dp[N - 1][i][j]);
        }
    }
    cout << res << endl;
    return 0;
}
0