結果
問題 | No.314 ケンケンパ |
ユーザー |
![]() |
提出日時 | 2016-07-09 05:40:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 91 ms / 1,000 ms |
コード長 | 617 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 32,768 KB |
実行使用メモリ | 117,504 KB |
最終ジャッジ日時 | 2024-10-13 08:10:49 |
合計ジャッジ時間 | 1,486 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <cstdio> #include <cstring> using namespace std; const int mod = 1e9+7; int n; long long dp[1111111][2][3]; long long solve(int a, int b, int c) { if (dp[a][b][c] >= 0) return dp[a][b][c]; if (a == n) return 1; long long res = 0; if (b == 0) { if (c < 2) { res = (res+solve(a+1, 0, c+1))%mod; } if (c > 0) { res = (res+solve(a+1, 1, 0))%mod; } } else { res = (res+solve(a+1, 0, c+1))%mod; } return dp[a][b][c] = res; } int main(void) { scanf("%d", &n); memset(dp, -1, sizeof(dp)); long long res = solve(0, 0, 0); printf("%lld\n", res); return 0; }