結果

問題 No.314 ケンケンパ
コンテスト
ユーザー mamekin
提出日時 2015-12-20 13:29:02
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 1,000 ms
コード長 976 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 582 ms
コンパイル使用メモリ 111,492 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-06 06:50:51
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;

    vector<int> dp(3);
    dp[0] = 1;
    for(int i=0; i<n; ++i){
        vector<int> nextDp(3);
        for(int j=0; j<3; ++j){
            if(j > 0){
                nextDp[0] += dp[j];
                nextDp[0] %= MOD;
            }
            if(j < 2){
                nextDp[j+1] += dp[j];
                nextDp[j+1] %= MOD;
            }
        }
        dp.swap(nextDp);
    }

    int ans = 0;
    for(int i=0; i<3; ++i){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}
0