結果

問題 No.3157 Nabeatsu
ユーザー urectanc
提出日時 2025-05-23 19:39:26
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 28,555 ms
コンパイル使用メモリ 397,164 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-23 19:39:59
合計ジャッジ時間 15,213 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::{input, marker::Bytes};

fn main() {
    input! { a: Bytes }

    let n = a.len();
    let mut a = a.into_iter().map(|n| n - b'0').collect::<Vec<_>>();
    for i in 0..n {
        if a[i] == 3 {
            a[i] -= 1;
            for j in i + 1..n {
                a[j] = 9;
            }
            break;
        }
    }

    let digit_sum = a.iter().fold(0u8, |acc, &e| (acc + e) % 3);
    if digit_sum == 0 {
        for i in (0..n).rev() {
            if a[i] == 0 {
                a[i] = 9;
            } else {
                a[i] -= 1;
                if a[i] == 3 {
                    a[i] -= 1;
                }
                break;
            }
        }
    }

    let ans = a.iter().map(|&a| (a + b'0') as char).collect::<String>();
    println!("{}", ans);
}
0