Submission #2207060


Source Code Expand

/**
*  _           _                 __                            _   _ _   _                                 _                    _                  _
* | |         | |               / /                           | | (_) | (_)                               | |                  (_)                | |
* | |__   __ _| |_ ___   ___   / /__ ___  _ __ ___  _ __   ___| |_ _| |_ ___   _____ ______ _ __ _   _ ___| |_ ______ ___ _ __  _ _ __  _ __   ___| |_ ___
* | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __|
* | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) |  __/ |_| | |_| |\ V /  __/      | |  | |_| \__ \ |_       \__ \ | | | | |_) | |_) |  __/ |_\__ \
* |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___|      |_|   \__,_|___/\__|      |___/_| |_|_| .__/| .__/ \___|\__|___/
*                                                  | |                                                                           | |   | |
*                                                  |_|                                                                           |_|   |_|
*
* https://github.com/hatoo/competitive-rust-snippets
*/
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
#[allow(dead_code)]
pub const INF: u64 = 1 << 60;
fn solve() {
    let k = get!(u64);

    let mut ds = vec![INF; k as usize];
    let mut que = VecDeque::new();
    que.push_back((1, 1 % k));

    while let Some((c, x)) = que.pop_front() {
        if x == 0 {
            println!("{}", c);
            return;
        }

        if ds[x as usize] > c {
            ds[x as usize] = c;
            que.push_front((c, (x * 10) % k));
            que.push_back((c + 1, (x + 1) % k));
        }
    }
}

Submission Info

Submission Time
Task D - Small Multiple
User hatoo
Language Rust (1.15.1)
Score 700
Code Size 4627 Byte
Status AC
Exec Time 7 ms
Memory 12668 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 67
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 3 ms 8572 KB
02.txt AC 3 ms 8572 KB
03.txt AC 3 ms 8572 KB
04.txt AC 3 ms 8572 KB
05.txt AC 3 ms 8572 KB
06.txt AC 3 ms 8572 KB
07.txt AC 3 ms 8572 KB
08.txt AC 3 ms 8572 KB
09.txt AC 3 ms 8572 KB
10.txt AC 3 ms 8572 KB
11.txt AC 3 ms 8572 KB
12.txt AC 3 ms 8572 KB
13.txt AC 3 ms 8572 KB
14.txt AC 3 ms 8572 KB
15.txt AC 3 ms 8572 KB
16.txt AC 3 ms 8572 KB
17.txt AC 3 ms 8572 KB
18.txt AC 3 ms 8572 KB
19.txt AC 3 ms 8572 KB
20.txt AC 3 ms 8572 KB
21.txt AC 3 ms 8572 KB
22.txt AC 6 ms 8572 KB
23.txt AC 6 ms 10620 KB
24.txt AC 7 ms 12668 KB
25.txt AC 6 ms 10620 KB
26.txt AC 4 ms 8572 KB
27.txt AC 6 ms 10620 KB
28.txt AC 6 ms 12668 KB
29.txt AC 4 ms 8572 KB
30.txt AC 7 ms 12668 KB
31.txt AC 3 ms 8572 KB
32.txt AC 3 ms 8572 KB
33.txt AC 5 ms 10620 KB
34.txt AC 3 ms 8572 KB
35.txt AC 5 ms 10620 KB
36.txt AC 3 ms 8572 KB
37.txt AC 3 ms 8572 KB
38.txt AC 3 ms 8572 KB
39.txt AC 4 ms 8572 KB
40.txt AC 3 ms 8572 KB
41.txt AC 4 ms 8572 KB
42.txt AC 6 ms 10620 KB
43.txt AC 3 ms 8572 KB
44.txt AC 3 ms 8572 KB
45.txt AC 4 ms 8572 KB
46.txt AC 4 ms 8572 KB
47.txt AC 3 ms 8572 KB
48.txt AC 5 ms 8572 KB
49.txt AC 5 ms 8572 KB
50.txt AC 4 ms 8572 KB
51.txt AC 3 ms 8572 KB
52.txt AC 4 ms 8572 KB
53.txt AC 5 ms 8572 KB
54.txt AC 4 ms 8572 KB
55.txt AC 4 ms 8572 KB
56.txt AC 5 ms 8572 KB
57.txt AC 6 ms 8572 KB
58.txt AC 4 ms 8572 KB
59.txt AC 5 ms 8572 KB
60.txt AC 5 ms 8572 KB
61.txt AC 3 ms 8572 KB
62.txt AC 4 ms 8572 KB
63.txt AC 6 ms 8572 KB
64.txt AC 6 ms 8572 KB
s1.txt AC 3 ms 8572 KB
s2.txt AC 3 ms 8572 KB
s3.txt AC 6 ms 8572 KB