結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー urectanc
提出日時 2026-08-31 21:57:00
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 934 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 525 ms
コンパイル使用メモリ 183,984 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-31 21:57:48
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

fn main() {
    input! {
        mut n: Bytes
    }
    n.iter_mut().for_each(|n| *n -= b'0');

    let mut ans = vec![];
    let mut less = false;
    for &n in &n {
        if less {
            ans.push(5);
        } else {
            if n > 5 {
                ans.push(5);
                less = true;
            } else if n < 4 {
                if let Some(i) = (0..ans.len()).rfind(|&i| ans[i] == 5) {
                    ans[i] -= 1;
                    ans.push(5);
                } else {
                    ans.truncate(ans.len().saturating_sub(1));
                    ans.fill(5);
                    if !ans.is_empty() {
                        ans.push(5);
                    }
                }
                less = true;
            } else {
                ans.push(n);
            }
        }
    }
    println!("{}", ans.iter().join(""));
}
0