結果
問題 |
No.1885 Flat Permutation
|
ユーザー |
|
提出日時 | 2022-10-17 12:19:44 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 802 bytes |
コンパイル時間 | 12,628 ms |
コンパイル使用メモリ | 378,832 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 02:51:24 |
合計ジャッジ時間 | 14,504 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
const MOD: usize = 998244353; fn main() { let mut nxy = String::new(); std::io::stdin().read_line(&mut nxy).ok(); let nxy: Vec<usize> = nxy.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nxy[0]; let x = nxy[1]; let y = nxy[2]; let (x, y) = (x.min(y), x.max(y)); if x > 1 && y < n && y-x == 1 { println!("0"); return; } let start = if x == 1 { 1 } else { x + 1 }; let end = if y == n { n } else { y - 1 }; let n = end-start; let mut dp = vec![0usize; n+1]; dp[0] = 1; for i in 0..n { if i+1 <= n { dp[i+1] += dp[i]; dp[i+1] %= MOD; } if i+3 <= n { dp[i+3] += dp[i]; dp[i+3] %= MOD; } } println!("{}", dp[n]); }