結果

問題 No.554 recurrence formula
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-12 00:35:10
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 647 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 74,260 KB
実行使用メモリ 41,716 KB
最終ジャッジ日時 2024-04-21 00:17:13
合計ジャッジ時間 5,483 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 122 ms
41,032 KB
testcase_02 AC 125 ms
41,708 KB
testcase_03 AC 124 ms
41,320 KB
testcase_04 AC 113 ms
39,888 KB
testcase_05 AC 110 ms
40,300 KB
testcase_06 AC 123 ms
41,240 KB
testcase_07 AC 123 ms
41,716 KB
testcase_08 AC 121 ms
41,044 KB
testcase_09 AC 108 ms
39,992 KB
testcase_10 AC 123 ms
41,184 KB
testcase_11 AC 127 ms
41,028 KB
testcase_12 AC 130 ms
41,348 KB
testcase_13 AC 130 ms
41,692 KB
testcase_14 AC 126 ms
41,292 KB
testcase_15 AC 124 ms
41,044 KB
testcase_16 AC 125 ms
41,404 KB
testcase_17 AC 114 ms
40,260 KB
testcase_18 AC 118 ms
40,920 KB
testcase_19 AC 121 ms
41,176 KB
testcase_20 AC 124 ms
41,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long MOD = (long)Math.pow(10, 9) + 7;
    long[] dp = new long[(int)n + 1];
    long oddsum = 0;
    long evensum = 0;
    dp[1] = 1;
    oddsum = 1;
    dp[2] = 2;
    evensum = 2;
    for(long i = 3; i < n + 1; i++) {
      if(i % 2 == 0) {
        dp[(int)i] = (i * oddsum) % MOD;
        evensum = (evensum + dp[(int)i]) % MOD;
      } else {
        dp[(int)i] = (i * evensum) % MOD;
        oddsum = (oddsum + dp[(int)i]) % MOD;
      }
    }
    System.out.println(dp[(int)n]);
  }
}
0