結果

問題 No.554 recurrence formula
ユーザー OlderInvestorOlderInvestor
提出日時 2017-10-29 17:24:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,402 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 3,725 ms
コンパイル使用メモリ 72,516 KB
実行使用メモリ 56,204 KB
最終ジャッジ日時 2023-08-14 09:41:19
合計ジャッジ時間 10,171 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,080 KB
testcase_01 AC 111 ms
55,680 KB
testcase_02 AC 113 ms
56,164 KB
testcase_03 AC 112 ms
55,708 KB
testcase_04 AC 113 ms
55,952 KB
testcase_05 AC 110 ms
56,204 KB
testcase_06 AC 110 ms
39,512 KB
testcase_07 AC 114 ms
39,560 KB
testcase_08 AC 111 ms
39,608 KB
testcase_09 AC 111 ms
39,500 KB
testcase_10 AC 127 ms
40,044 KB
testcase_11 AC 126 ms
39,652 KB
testcase_12 AC 118 ms
39,376 KB
testcase_13 AC 127 ms
40,008 KB
testcase_14 AC 124 ms
39,676 KB
testcase_15 AC 128 ms
39,784 KB
testcase_16 AC 130 ms
39,864 KB
testcase_17 AC 126 ms
39,488 KB
testcase_18 AC 126 ms
39,440 KB
testcase_19 AC 1,402 ms
40,040 KB
testcase_20 AC 1,375 ms
40,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class No554 {
    private int n;
    private long[] a;
    private long sumtmp;

    public static void main(String[] args) {
        No554 main = new No554();
        main.run();
    }

    private void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new long[n + 1];

        a[1] = 1;
        for(int i = 2; i < a.length; i++) {
            if(i % 2 == 1) {
                //a[i] = odd(i);
                sumtmp = 0;
                for(int j = 2; j < i; j += 2) {
                    sumtmp += a[j];
                }
                a[i] = i * sumtmp % 1000000007;
            } else {
                //a[i] = even(i);
                sumtmp = 0;
                for(int j = 1; j < i; j += 2) {
                    sumtmp += a[j];
                }
                a[i] = i * sumtmp % 1000000007;
            }
        }
        System.out.println(a[n] % 1000000007);
    }
}
0