結果

問題 No.1185 完全な3の倍数
ユーザー phspls
提出日時 2020-09-05 19:59:01
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 14,165 ms
コンパイル使用メモリ 376,668 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-11-29 06:00:31
合計ジャッジ時間 16,201 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

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: u64 = n.trim().parse().unwrap(); 

    let pattern: Vec<u64> = vec![0,3,6,9];
    let mut cands: VecDeque<u64> = VecDeque::new();
    let mut result: u64 = 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 * 10u64.pow(i as u32) as u64);
            }
        }
    }
    result += cands.iter().filter(|&i| i >= &100u64 && i <= &n).count() as u64;
    println!("{}", result);
}
0