結果

問題 No.554 recurrence formula
ユーザー OlderInvestorOlderInvestor
提出日時 2017-10-29 15:07:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 57,756 KB
最終ジャッジ日時 2023-08-14 09:34:39
合計ジャッジ時間 9,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,856 KB
testcase_01 AC 124 ms
56,020 KB
testcase_02 AC 125 ms
56,088 KB
testcase_03 AC 124 ms
55,392 KB
testcase_04 AC 125 ms
55,744 KB
testcase_05 AC 124 ms
55,736 KB
testcase_06 AC 125 ms
55,896 KB
testcase_07 AC 123 ms
56,080 KB
testcase_08 AC 124 ms
56,092 KB
testcase_09 AC 126 ms
56,068 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class No554 {
    private int n;
    private int[] a;
    private int 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 int[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]);
    }

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

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