結果

問題 No.1185 完全な3の倍数
ユーザー phspls
提出日時 2020-09-05 19:54:03
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 11,151 ms
コンパイル使用メモリ 400,592 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-29 05:59:22
合計ジャッジ時間 12,709 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;
use std::cmp::min;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: u32 = n.trim().parse().unwrap(); 

    let pattern: Vec<u32> = vec![0,3,6,9];
    let mut cands: VecDeque<u32> = VecDeque::new();
    let mut result: u32 = 0;
    for i in 10..min(n+1, 100) {
        if i % 3 == 0 && (i % 10 + i / 10) % 3 == 0 {
            result += 1;
        }
    }
    cands.push_back(0);
    for i in 0..(n.to_string().len()) {
        let limit = cands.len();
        for _ in 0..limit {
            let temp = cands.pop_front().unwrap();
            for j in pattern.iter() {
                cands.push_back(temp + j * 10u32.pow(i as u32) as u32);
            }
        }
    }
    result += cands.iter().filter(|&i| i >= &100u32 && i <= &n).count() as u32;
    println!("{}", result);
}
0