結果

問題 No.554 recurrence formula
ユーザー OlderInvestorOlderInvestor
提出日時 2017-10-29 15:33:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,088 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 4,394 ms
コンパイル使用メモリ 72,316 KB
実行使用メモリ 57,524 KB
最終ジャッジ日時 2023-08-14 09:36:58
合計ジャッジ時間 10,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,648 KB
testcase_01 AC 126 ms
56,180 KB
testcase_02 AC 127 ms
55,424 KB
testcase_03 AC 127 ms
55,716 KB
testcase_04 AC 127 ms
55,732 KB
testcase_05 AC 126 ms
55,520 KB
testcase_06 AC 126 ms
55,564 KB
testcase_07 AC 126 ms
55,932 KB
testcase_08 AC 128 ms
55,468 KB
testcase_09 AC 126 ms
56,000 KB
testcase_10 AC 138 ms
55,684 KB
testcase_11 AC 139 ms
55,376 KB
testcase_12 AC 138 ms
55,784 KB
testcase_13 AC 143 ms
55,856 KB
testcase_14 AC 137 ms
55,784 KB
testcase_15 AC 145 ms
55,852 KB
testcase_16 AC 146 ms
57,524 KB
testcase_17 AC 140 ms
55,712 KB
testcase_18 AC 140 ms
55,836 KB
testcase_19 AC 1,082 ms
55,980 KB
testcase_20 AC 1,088 ms
55,704 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);
            } else {
                a[i] = even(i);
            }
        }
        System.out.println(a[n] % 1000000007);
    }

    private long odd(int n) {
        sumtmp = 0;
        for(int i = 2; i < n; i += 2) {
            sumtmp += a[i];
        }
        return n * sumtmp % 1000000007;
    }

    private long even(int n) {
        sumtmp = 0;
        for(int i = 1; i < n; i += 2) {
            sumtmp += a[i];
        }
        return n * sumtmp % 1000000007;
    }
}
0