結果

問題 No.554 recurrence formula
ユーザー 37zigen37zigen
提出日時 2017-08-12 00:58:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 2,807 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 42,972 KB
最終ジャッジ日時 2024-04-21 00:23:30
合計ジャッジ時間 6,012 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
39,892 KB
testcase_01 AC 108 ms
40,232 KB
testcase_02 AC 118 ms
41,072 KB
testcase_03 AC 117 ms
41,032 KB
testcase_04 AC 111 ms
39,448 KB
testcase_05 AC 121 ms
41,104 KB
testcase_06 AC 105 ms
39,884 KB
testcase_07 AC 118 ms
41,160 KB
testcase_08 AC 119 ms
41,004 KB
testcase_09 AC 123 ms
41,124 KB
testcase_10 AC 118 ms
40,252 KB
testcase_11 AC 123 ms
41,088 KB
testcase_12 AC 125 ms
41,340 KB
testcase_13 AC 119 ms
40,396 KB
testcase_14 AC 121 ms
41,400 KB
testcase_15 AC 127 ms
41,416 KB
testcase_16 AC 112 ms
40,096 KB
testcase_17 AC 121 ms
41,240 KB
testcase_18 AC 125 ms
41,408 KB
testcase_19 AC 130 ms
42,736 KB
testcase_20 AC 129 ms
42,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n + 1];
		a[1] = 1;
		long[][] s = new long[2][n + 1];
		s[1][1] = 1;
		for (int i = 2; i <= n; ++i) {
			a[i] = i * s[1 - i % 2][i - 1] % MODULO;
			s[i % 2][i] = s[i % 2][i - 1] + a[i];
			s[1 - i % 2][i] = s[1 - i % 2][i - 1];
			a[i] %= MODULO;
			s[i % 2][i] %= MODULO;
		}
		System.out.println(a[n]);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

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