結果

問題 No.554 recurrence formula
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-12 00:36:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 41,696 KB
最終ジャッジ日時 2024-04-21 00:17:38
合計ジャッジ時間 5,740 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
40,108 KB
testcase_01 AC 129 ms
41,332 KB
testcase_02 AC 132 ms
40,904 KB
testcase_03 AC 120 ms
39,672 KB
testcase_04 AC 133 ms
41,204 KB
testcase_05 AC 131 ms
41,116 KB
testcase_06 AC 132 ms
41,004 KB
testcase_07 AC 131 ms
41,276 KB
testcase_08 AC 116 ms
39,944 KB
testcase_09 AC 132 ms
41,368 KB
testcase_10 AC 134 ms
41,508 KB
testcase_11 AC 131 ms
41,500 KB
testcase_12 AC 131 ms
41,076 KB
testcase_13 AC 130 ms
40,920 KB
testcase_14 AC 134 ms
41,200 KB
testcase_15 AC 132 ms
41,052 KB
testcase_16 AC 133 ms
41,108 KB
testcase_17 AC 131 ms
40,964 KB
testcase_18 AC 121 ms
39,808 KB
testcase_19 AC 128 ms
40,656 KB
testcase_20 AC 139 ms
41,696 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 + 2];
    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