結果
| 問題 |
No.3157 Nabeatsu
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-24 11:35:12 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,225 bytes |
| コンパイル時間 | 12,446 ms |
| コンパイル使用メモリ | 400,448 KB |
| 実行使用メモリ | 7,936 KB |
| 最終ジャッジ日時 | 2025-05-24 11:35:29 |
| 合計ジャッジ時間 | 15,201 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 3 |
ソースコード
use proconio::{input, marker::Chars};
use std::iter;
fn main() {
input! {
n: Chars
}
let pos3 = n.iter().position(|&x| x == '3');
let rem = n[..pos3.unwrap_or(n.len())].iter().map(|&c| c as usize - '0' as usize).sum::<usize>() % 3;
match pos3 {
Some(pos3) if pos3 == n.len() - 1 => {
if rem == 1 {
println!("{}1", n[..pos3].iter().collect::<String>())
} else {
println!("{}2", n[..pos3].iter().collect::<String>())
}
},
Some(pos3) => {
println!("{}2{}{}",
n[..pos3].iter().collect::<String>(),
iter::repeat('9').take(n.len() - pos3 - 2).collect::<String>(),
if rem == 1 { '8' } else { '9' });
},
None if rem % 3 != 0 => println!("{}", n.into_iter().collect::<String>()),
None => {
let last_not0_pos = n.iter().rposition(|&x| x != '0').unwrap();
println!("{}{}{}",
n[..last_not0_pos].iter().collect::<String>(),
n[last_not0_pos] as usize - '0' as usize - 1,
iter::repeat('9').take(n.len() - last_not0_pos - 1).collect::<String>());
}
}
}