結果

問題 No.2455 Numbers Dictionary
ユーザー koba-e964koba-e964
提出日時 2023-09-16 01:59:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,494 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 144,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 01:59:37
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 24 ms
4,376 KB
testcase_03 AC 20 ms
4,376 KB
testcase_04 AC 19 ms
4,376 KB
testcase_05 AC 24 ms
4,380 KB
testcase_06 AC 24 ms
4,376 KB
testcase_07 AC 24 ms
4,376 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 23 ms
4,376 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 23 ms
4,380 KB
testcase_21 AC 24 ms
4,376 KB
testcase_22 AC 20 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// If p10 = 10^k, this function returns a k-digit number
// that is obtained as floor(n * 10^?).
fn pick_digits(mut n: i64, p10: i64) -> i64 {
    if n < p10 / 10 {
        while n < p10 / 10 {
            n *= 10;
        }
        return n;
    }
    while n >= p10 {
        n /= 10;
    }
    n
}

fn main() {
    let t: i32 = get();
    for _ in 0..t {
        let n: i64 = get();
        let k: i64 = get();
        let mut p = 1;
        while p <= n {
            p *= 10;
        }
        let mut ans = 0;
        while p > 1 {
            p /= 10;
            // [p, cur)
            let cur = pick_digits(k, 10 * p);
            let l = p;
            let r = min(cur + 1, min(n + 1, if cur > k { cur } else { cur + 1 }));
            if l < r {
                ans += r - l;
            }
        }
        println!("{}", ans);
    }
}
0