結果
問題 | No.1492 01文字列と転倒 |
ユーザー |
|
提出日時 | 2023-01-09 18:11:37 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 404 ms / 4,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 12,115 ms |
コンパイル使用メモリ | 395,644 KB |
実行使用メモリ | 9,728 KB |
最終ジャッジ日時 | 2024-12-17 20:42:43 |
合計ジャッジ時間 | 16,625 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
コンパイルメッセージ
warning: variable `MOD` should have a snake case name --> src/main.rs:7:9 | 7 | let MOD = nm[1]; | ^^^ | = note: `#[warn(non_snake_case)]` on by default help: rename the identifier or convert it to a snake case raw identifier | 7 | let r#mod = nm[1]; | ~~~~~
ソースコード
fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let MOD = nm[1]; let limit = (0..n).sum::<usize>(); let mut dp = vec![vec![0usize; limit+1]; n+1]; dp[0][0] = 1; for i in 1..2*n { let mut next_dp = vec![vec![0usize; limit+1]; n+1]; for cnt1 in 0..=i/2 { for inv_val in 0..=limit { if dp[cnt1][inv_val] == 0 { continue; } let used0 = i - cnt1; let used1 = cnt1; if used0 < n { next_dp[used1][inv_val] += dp[used1][inv_val]; next_dp[used1][inv_val] %= MOD; } if used1+1 <= used0 { let ninv_val = n - used0 + inv_val; next_dp[used1+1][ninv_val] += dp[used1][inv_val]; next_dp[used1+1][ninv_val] %= MOD; } } } dp = next_dp; } for i in 0..=limit { println!("{}", dp[n][i]); } for _ in limit+1..=n*n { println!("0"); } }