結果
問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
ユーザー |
|
提出日時 | 2025-10-03 23:12:01 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 1,466 bytes |
コンパイル時間 | 29,446 ms |
コンパイル使用メモリ | 401,028 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-03 23:12:37 |
合計ジャッジ時間 | 15,952 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
use proconio::input; fn main() { input! { (n, k): (usize, u64), t: String, } let encrypt = t .chars() .map(|ch| ch.to_digit(10).unwrap() as u64) .collect::<Vec<_>>(); let mut suffix_num_combs = vec![0_u64; n + 2]; suffix_num_combs[n] = 1; for i in (0..n).rev() { let num_combs_1 = suffix_num_combs[i + 1] * valid_encryption(&encrypt[i..i + 1]) as u64; let num_combs_2 = suffix_num_combs[i + 2] * (i + 1 < n && valid_encryption(&encrypt[i..i + 2])) as u64; suffix_num_combs[i] = num_combs_1.saturating_add(num_combs_2); } let mut plaintext = String::new(); let mut overcome = 0_u64; let mut progress = 0_usize; while progress < n { if valid_encryption(&encrypt[progress..progress + 1]) && overcome + suffix_num_combs[progress + 1] >= k { plaintext.push((b'a' + encrypt[progress] as u8 - 1) as char); progress += 1; } else { plaintext .push((b'a' + (10 * encrypt[progress] + encrypt[progress + 1]) as u8 - 1) as char); overcome += suffix_num_combs[progress + 1]; progress += 2; } } println!("{plaintext}"); } fn valid_encryption(crypt: &[u64]) -> bool { match crypt.len() { 0 => true, 1 => crypt[0] != 0, 2 => crypt[0] != 0 && 10 * crypt[0] + crypt[1] <= 26, _ => false, } }