結果

問題 No.554 recurrence formula
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-11 23:21:06
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 890 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 77,168 KB
実行使用メモリ 43,672 KB
最終ジャッジ日時 2024-04-20 23:38:02
合計ジャッジ時間 5,614 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 109 ms
40,364 KB
testcase_02 AC 122 ms
41,052 KB
testcase_03 AC 109 ms
40,044 KB
testcase_04 AC 106 ms
39,588 KB
testcase_05 AC 123 ms
41,356 KB
testcase_06 AC 124 ms
41,448 KB
testcase_07 AC 112 ms
40,420 KB
testcase_08 AC 121 ms
41,376 KB
testcase_09 AC 110 ms
40,516 KB
testcase_10 AC 121 ms
41,368 KB
testcase_11 AC 124 ms
41,528 KB
testcase_12 AC 127 ms
41,200 KB
testcase_13 AC 120 ms
41,136 KB
testcase_14 AC 118 ms
40,420 KB
testcase_15 AC 128 ms
41,648 KB
testcase_16 AC 113 ms
40,148 KB
testcase_17 AC 126 ms
41,612 KB
testcase_18 AC 114 ms
40,416 KB
testcase_19 AC 136 ms
43,672 KB
testcase_20 AC 135 ms
43,500 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 = new long[(int)n + 1];
    long[] evensum = new long[(int)n + 1];
    dp[1] = 1;
    oddsum[1] = 1;
    evensum[1] = 0;
    dp[2] = 2;
    oddsum[2] = 1;
    evensum[2] = 2;
    for(long i = 3; i < n + 1; i++) {
      if(i % 2 == 0) {
        dp[(int)i] = (i * oddsum[(int)i - 1]) % MOD;
        oddsum[(int)i] = oddsum[(int)i - 1];
        evensum[(int)i] = (evensum[(int)i - 2] + dp[(int)i]) % MOD;
      } else {
        dp[(int)i] = (i * evensum[(int)i - 1]) % MOD;
        oddsum[(int)i] = (oddsum[(int)i - 2] + dp[(int)i]) % MOD;
        evensum[(int)i] = evensum[(int)i - 1];
      }
    }
    System.out.println(dp[(int)n]);
  }
}
0