結果
| 問題 |
No.741 AscNumber(Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-08 12:17:50 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 489 ms / 2,000 ms |
| コード長 | 1,108 bytes |
| コンパイル時間 | 14,224 ms |
| コンパイル使用メモリ | 381,476 KB |
| 実行使用メモリ | 197,288 KB |
| 最終ジャッジ日時 | 2024-10-12 14:30:22 |
| 合計ジャッジ時間 | 29,557 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 |
ソースコード
use std::io;
const MOD: u64 = 1_000_000_007;
struct F {
// i桁のjで始まるAscNumberはいくつあるか
// 1 <= i <= 1000000
// 1 <= j <= 9
memo: Vec<Vec<Option<u64>>>,
}
impl F {
fn new() -> Self {
let mut memo = vec![vec![None; 10]; 1000001];
for j in 1..10 {
memo[1][j] = Some(1);
}
Self {
memo,
}
}
fn call(&mut self, i: usize, j: usize) -> u64 {
debug_assert!(1 <= i && i <= 1000000);
debug_assert!(1 <= j && j <= 9);
if let Some(res) = self.memo[i][j] { return res; }
let mut res = 0;
for j2 in j..10 {
res += self.call(i-1, j2);
res %= MOD;
}
self.memo[i][j] = Some(res);
res
}
}
fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let n: usize = s.trim().parse().unwrap();
let mut f = F::new();
let mut ans = 1; // 0 もAscNumber
for i in 1..n+1 { for j in 1..10 {
ans += f.call(i,j);
ans %= MOD;
}}
println!("{}", ans);
}