結果

問題 No.2329 Nafmo、イカサマをする
ユーザー titiatitia
提出日時 2023-07-25 04:35:05
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,256 bytes
コンパイル時間 1,361 ms
コンパイル使用メモリ 184,488 KB
実行使用メモリ 193,412 KB
最終ジャッジ日時 2024-04-09 22:23:09
合計ジャッジ時間 6,113 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 0 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 13 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 0 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 36 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 0 ms
6,944 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 326 ms
20,416 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 169 ms
18,108 KB
testcase_40 AC 80 ms
9,424 KB
testcase_41 TLE -
testcase_42 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io`
 --> main.rs:2:5
  |
2 | use std::io;
  |     ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: the item `io` is imported redundantly
  --> main.rs:18:24
   |
2  | use std::io;
   |     ------- the item `io` is already imported here
...
18 |         .collect();use std::io;
   |                        ^^^^^^^

warning: unused variable: `n`
 --> main.rs:8:9
  |
8 |     let n: usize = iter.next().unwrap().parse().unwrap();
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `n`
  --> main.rs:24:9
   |
24 |     let n: usize = iter.next().unwrap().parse().expect("Failed to parse N");
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`

warning: function `main` is never used
  --> main.rs:20:4
   |
20 | fn main() {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 5 warnings emitted

ソースコード

diff #

use std::collections::HashSet;
use std::io;

fn main() {
    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    let mut iter = input_line.trim().split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    let a: Vec<usize> = input_line
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    let mut iter = input.trim().split_whitespace();
    let n: usize = iter.next().unwrap().parse().expect("Failed to parse N");
    let m: i32 = iter.next().unwrap().parse().expect("Failed to parse M");
    let k: usize = iter.next().unwrap().parse().expect("Failed to parse K");

    input.clear();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    let a: Vec<i32> = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse().expect("Failed to parse element of A"))
        .collect();

    let mut s = vec![false; m as usize + 1];
    s[0] = true;

    for _ in 0..k {
        let mut ns = vec![false; m as usize + 1];
        ns[0] = true;

        for i in 0..s.len() {
            if s[i] {
                for &ai in &a {
                    let idx = i as i32 + ai;
                    if idx <= m {
                        ns[idx as usize] = true;
                    }
                }
            }
        }

        s = ns;
    }

    let result = s.iter().rposition(|&x| x).unwrap_or(0);
    println!("{}", result);
}


    let mut s: HashSet<usize> = HashSet::new();
    s.insert(0);

    for _ in 0..k {
        let mut ns: HashSet<usize> = HashSet::new();
        ns.insert(0);

        for &si in &s {
            for &ai in &a {
                if si + ai <= m {
                    ns.insert(si + ai);
                }
            }
        }

        s = ns;
    }

    if let Some(&max_val) = s.iter().max() {
        println!("{}", max_val);
    }
}
0