結果

問題 No.314 ケンケンパ
ユーザー hogeover30
提出日時 2015-12-07 06:11:26
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 465 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 21,632 KB
実行使用メモリ 24,832 KB
最終ジャッジ日時 2024-09-14 18:05:36
合計ジャッジ時間 1,156 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
   18 |     printf("%d\n", res%mod);
      |             ~^     ~~~~~~~
      |              |        |
      |              int      long int
      |             %ld
main.c:8:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d", &n);
      |     ^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
const long mod=1e9+7;
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;
    }
    long res=0;
    for(i=0;i<3;++i) res+=dp[n][i];
    printf("%d\n", res%mod);
}

0