結果
| 問題 | No.554 recurrence formula |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-11 22:35:06 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 789 bytes |
| 記録 | |
| コンパイル時間 | 2,815 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 43,632 KB |
| 最終ジャッジ日時 | 2026-04-30 01:05:30 |
| 合計ジャッジ時間 | 5,283 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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);
}
}
}