結果

問題 No.2784 繰り上がりなし十進和
ユーザー titiatitia
提出日時 2024-06-20 03:25:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 28,598 ms
コンパイル使用メモリ 402,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-20 03:25:37
合計ジャッジ時間 19,572 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 294 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 322 ms
6,944 KB
testcase_13 AC 294 ms
6,944 KB
testcase_14 AC 80 ms
6,944 KB
testcase_15 AC 18 ms
6,944 KB
testcase_16 AC 41 ms
6,944 KB
testcase_17 AC 167 ms
6,944 KB
testcase_18 AC 192 ms
6,940 KB
testcase_19 AC 42 ms
6,944 KB
testcase_20 AC 317 ms
6,944 KB
testcase_21 AC 50 ms
6,944 KB
testcase_22 AC 331 ms
6,940 KB
testcase_23 AC 20 ms
6,940 KB
testcase_24 AC 88 ms
6,940 KB
testcase_25 AC 167 ms
6,944 KB
testcase_26 AC 398 ms
6,940 KB
testcase_27 AC 366 ms
6,940 KB
testcase_28 AC 87 ms
6,940 KB
testcase_29 AC 385 ms
6,940 KB
testcase_30 AC 106 ms
6,944 KB
testcase_31 AC 38 ms
6,940 KB
testcase_32 AC 160 ms
6,940 KB
testcase_33 AC 188 ms
6,940 KB
testcase_34 AC 78 ms
6,940 KB
testcase_35 AC 26 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `A` should have a snake case name
 --> src/main.rs:8:13
  |
8 |     let mut A = Vec::new();
  |             ^ help: convert the identifier to snake case: `a`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `U` should have a snake case name
  --> src/main.rs:14:9
   |
14 |     let U: Vec<i32> = (0..6).map(|i| 10i32.pow(i)).collect();
   |         ^ help: convert the identifier to snake case (notice the capitalization): `u`

warning: variable `U` should have a snake case name
  --> src/main.rs:17:29
   |
17 |     fn calc(x: i32, y: i32, U: &Vec<i32>) -> i32 {
   |                             ^ help: convert the identifier to snake case (notice the capitalization): `u`

warning: variable `ANS` should have a snake case name
  --> src/main.rs:18:17
   |
18 |         let mut ANS = 0;
   |                 ^^^ help: convert the identifier to snake case: `ans`

warning: variable `DP` should have a snake case name
  --> src/main.rs:26:13
   |
26 |     let mut DP = vec![0; 1_000_000];
   |             ^^ help: convert the identifier to snake case: `dp`

warning: variable `Q` should have a snake case name
  --> src/main.rs:28:13
   |
28 |     let mut Q = VecDeque::new();
   |             ^ help: convert the identifier to snake case: `q`

ソースコード

diff #

use std::collections::VecDeque;
use std::io::{self, BufRead};

fn main() {
    // Read input
    let stdin = io::stdin();
    let mut iterator = stdin.lock().lines();
    let mut A = Vec::new();
    for _ in 0..6 {
        A.push(iterator.next().unwrap().unwrap().parse::<i32>().unwrap());
    }

    // Generate U array
    let U: Vec<i32> = (0..6).map(|i| 10i32.pow(i)).collect();

    // Function to calculate the result
    fn calc(x: i32, y: i32, U: &Vec<i32>) -> i32 {
        let mut ANS = 0;
        for &i in U.iter() {
            ANS += ((x / i + y / i) % 10) * i;
        }
        ANS
    }

    // DP array
    let mut DP = vec![0; 1_000_000];
    DP[0] = 1;
    let mut Q = VecDeque::new();
    Q.push_back(0);

    // Process the queue
    while let Some(x) = Q.pop_front() {
        for &a in A.iter() {
            let to = calc(a, x, &U);
            if DP[to as usize] == 0 {
                DP[to as usize] = 1;
                Q.push_back(to);
            }
        }
    }

    // Sum the DP array
    let result: i32 = DP.iter().sum();
    println!("{}", result);
}
0