結果
問題 | No.314 ケンケンパ |
ユーザー |
![]() |
提出日時 | 2015-12-07 06:12:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 32 ms / 1,000 ms |
コード長 | 492 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 23,680 KB |
実行使用メモリ | 24,960 KB |
最終ジャッジ日時 | 2024-09-14 18:05:40 |
合計ジャッジ時間 | 955 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:14: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] 18 | printf("%u\n", res%mod); | ~^ ~~~~~~~ | | | | | long unsigned int | unsigned int | %lu main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h>const unsigned long mod=1e9+7;unsigned long dp[1000010][3];int main(){int i, n;scanf("%d", &n);dp[0][0]=1;for(i=1;i<=n;++i) {if ((dp[i][1]+=dp[i-1][0])>=mod) dp[i][1]-=mod;if ((dp[i][2]+=dp[i-1][1])>=mod) dp[i][2]-=mod;if ((dp[i][0]+=dp[i-1][1])>=mod) dp[i][0]-=mod;if ((dp[i][0]+=dp[i-1][2])>=mod) dp[i][0]-=mod;}unsigned long res=0;for(i=0;i<3;++i) res+=dp[n][i];printf("%u\n", res%mod);}