結果
問題 |
No.2329 Nafmo、イカサマをする
|
ユーザー |
![]() |
提出日時 | 2023-07-25 04:35:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,256 bytes |
コンパイル時間 | 13,968 ms |
コンパイル使用メモリ | 378,084 KB |
実行使用メモリ | 20,492 KB |
最終ジャッジ日時 | 2024-10-01 22:58:17 |
合計ジャッジ時間 | 18,995 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 TLE * 1 -- * 1 |
コンパイルメッセージ
warning: unused import: `std::io` --> src/main.rs:2:5 | 2 | use std::io; | ^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: the item `io` is imported redundantly --> src/main.rs:18:24 | 2 | use std::io; | ------- the item `io` is already imported here ... 18 | .collect();use std::io; | ^^^^^^^ warning: unused variable: `n` --> src/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` --> src/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 --> src/main.rs:20:4 | 20 | fn main() { | ^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
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); } }