結果

問題 No.314 ケンケンパ
ユーザー whesonwheson
提出日時 2018-05-01 14:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 1,028 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 164,932 KB
実行使用メモリ 26,988 KB
最終ジャッジ日時 2023-09-10 08:43:46
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
26,912 KB
testcase_01 AC 10 ms
26,768 KB
testcase_02 AC 10 ms
26,968 KB
testcase_03 AC 9 ms
26,732 KB
testcase_04 AC 9 ms
26,916 KB
testcase_05 AC 10 ms
26,924 KB
testcase_06 AC 10 ms
26,840 KB
testcase_07 AC 9 ms
26,836 KB
testcase_08 AC 9 ms
26,720 KB
testcase_09 AC 10 ms
26,988 KB
testcase_10 AC 10 ms
26,756 KB
testcase_11 AC 10 ms
26,748 KB
testcase_12 AC 9 ms
26,732 KB
testcase_13 AC 10 ms
26,784 KB
testcase_14 AC 10 ms
26,772 KB
testcase_15 AC 9 ms
26,732 KB
testcase_16 AC 10 ms
26,760 KB
testcase_17 AC 10 ms
26,728 KB
testcase_18 AC 11 ms
26,736 KB
testcase_19 AC 13 ms
26,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
LL dp[1000005][3]; // dp[i][j] := iマス目のときj(0: パ, 1~2: ケンj回目)となる組み合わせの総数
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    REP(i, 1000005) REP(j, 3) dp[i][j] = 0;
    dp[1][1] = 1;
    for(int i = 2; i <= n; i++){
        dp[i][0] = (dp[i-1][1] + dp[i-1][2]) % MOD;
        dp[i][1] = dp[i-1][0];
        dp[i][2] = dp[i-1][1];
    }
    cout << (dp[n][0] + dp[n][1] + dp[n][2]) % MOD << endl;
}
0