結果

問題 No.554 recurrence formula
ユーザー GrenacheGrenache
提出日時 2017-08-11 22:32:04
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 789 bytes
コンパイル時間 2,959 ms
コンパイル使用メモリ 75,532 KB
実行使用メモリ 56,468 KB
最終ジャッジ日時 2024-04-20 22:47:34
合計ジャッジ時間 6,196 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 109 ms
52,852 KB
testcase_02 AC 120 ms
54,044 KB
testcase_03 AC 107 ms
53,276 KB
testcase_04 AC 114 ms
53,944 KB
testcase_05 AC 126 ms
54,196 KB
testcase_06 AC 113 ms
53,308 KB
testcase_07 AC 107 ms
52,932 KB
testcase_08 AC 122 ms
53,740 KB
testcase_09 AC 112 ms
52,896 KB
testcase_10 AC 125 ms
53,816 KB
testcase_11 AC 122 ms
53,948 KB
testcase_12 AC 120 ms
54,140 KB
testcase_13 AC 122 ms
53,872 KB
testcase_14 AC 120 ms
53,852 KB
testcase_15 AC 119 ms
54,332 KB
testcase_16 AC 121 ms
54,132 KB
testcase_17 AC 122 ms
54,392 KB
testcase_18 AC 118 ms
53,804 KB
testcase_19 AC 128 ms
56,020 KB
testcase_20 AC 127 ms
56,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder554 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		int n = sc.nextInt();

		long[] a = new long[n + 1];
		long[] sum = new long[n + 1];
		a[1] = 1;
		sum[1] = 1;
		a[2] = 2;
		sum[2] = 2;
		for (int i = 3; i <= n; i++) {
			a[i] = sum[i - 1] * i % MOD;
			sum[i] = sum[i - 2] + a[i];
			sum[i] %= MOD;
		}

		pr.println(a[n]);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0