結果

問題 No.1185 完全な3の倍数
ユーザー phsplsphspls
提出日時 2020-09-05 19:59:01
言語 Rust
(1.72.1)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 3,274 ms
コンパイル使用メモリ 146,552 KB
実行使用メモリ 10,068 KB
最終ジャッジ日時 2023-08-19 12:59:51
合計ジャッジ時間 2,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 5 ms
4,384 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 15 ms
10,068 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 4 ms
4,384 KB
testcase_20 AC 5 ms
4,384 KB
testcase_21 AC 5 ms
4,384 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 4 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 4 ms
4,384 KB
testcase_27 AC 4 ms
4,384 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 4 ms
4,384 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 5 ms
4,384 KB
testcase_35 AC 4 ms
4,384 KB
testcase_36 AC 4 ms
4,384 KB
testcase_37 AC 5 ms
4,384 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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