結果

問題 No.554 recurrence formula
ユーザー GrenacheGrenache
提出日時 2017-08-11 22:35:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 3,215 ms
コンパイル使用メモリ 74,816 KB
実行使用メモリ 42,812 KB
最終ジャッジ日時 2024-04-20 22:50:13
合計ジャッジ時間 6,152 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
40,280 KB
testcase_01 AC 119 ms
41,056 KB
testcase_02 AC 110 ms
40,268 KB
testcase_03 AC 115 ms
41,276 KB
testcase_04 AC 121 ms
41,568 KB
testcase_05 AC 110 ms
40,464 KB
testcase_06 AC 119 ms
41,344 KB
testcase_07 AC 118 ms
41,580 KB
testcase_08 AC 105 ms
41,568 KB
testcase_09 AC 121 ms
41,396 KB
testcase_10 AC 121 ms
41,512 KB
testcase_11 AC 119 ms
40,892 KB
testcase_12 AC 105 ms
40,008 KB
testcase_13 AC 121 ms
41,472 KB
testcase_14 AC 107 ms
40,404 KB
testcase_15 AC 109 ms
41,620 KB
testcase_16 AC 109 ms
40,204 KB
testcase_17 AC 110 ms
40,252 KB
testcase_18 AC 120 ms
41,236 KB
testcase_19 AC 121 ms
42,812 KB
testcase_20 AC 115 ms
41,940 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 + 2];
		long[] sum = new long[n + 2];
		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