結果
| 問題 |
No.554 recurrence formula
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-11 22:35:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 138 ms / 2,000 ms |
| コード長 | 789 bytes |
| コンパイル時間 | 3,383 ms |
| コンパイル使用メモリ | 74,804 KB |
| 実行使用メモリ | 42,976 KB |
| 最終ジャッジ日時 | 2024-10-12 21:17:39 |
| 合計ジャッジ時間 | 6,946 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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);
}
}
}