結果

問題 No.2784 繰り上がりなし十進和
ユーザー atcoder8
提出日時 2024-06-14 22:49:10
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1,626 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 11,426 ms
コンパイル使用メモリ 379,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-14 22:50:13
合計ジャッジ時間 30,071 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

const MAX: usize = 10_usize.pow(6);

fn main() {
    input! {
        aa: [usize; 6],
    }

    let mut visited = vec![false; MAX];
    for &a in &aa {
        visited[a] = true;

        for _ in 0..10 {
            for from in 0..MAX {
                if visited[from] {
                    let to = add_without_carry_up(from, a);
                    visited[to] = true;
                }
            }
        }
    }

    let ans = visited.iter().filter(|&&v| v).count();
    println!("{}", ans);
}

fn add_without_carry_up(a1: usize, a2: usize) -> usize {
    let s1 = format!("{:06}", a1);
    let s2 = format!("{:06}", a2);

    let mut c = 0;
    for (c1, c2) in s1.chars().zip(s2.chars()) {
        let d1 = c1.to_digit(10).unwrap() as usize;
        let d2 = c2.to_digit(10).unwrap() as usize;
        c = 10 * c + (d1 + d2) % 10;
    }

    c
}
0