結果
問題 | No.332 数列をプレゼントに |
ユーザー | koba-e964 |
提出日時 | 2017-01-11 00:51:56 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 822 ms / 2,000 ms |
コード長 | 3,176 bytes |
コンパイル時間 | 11,403 ms |
コンパイル使用メモリ | 378,332 KB |
実行使用メモリ | 199,424 KB |
最終ジャッジ日時 | 2024-06-06 16:51:50 |
合計ジャッジ時間 | 26,500 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 131 ms
57,856 KB |
testcase_06 | AC | 184 ms
83,072 KB |
testcase_07 | AC | 331 ms
144,896 KB |
testcase_08 | AC | 186 ms
85,760 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 8 ms
5,376 KB |
testcase_11 | AC | 113 ms
51,840 KB |
testcase_12 | AC | 355 ms
158,464 KB |
testcase_13 | AC | 209 ms
96,256 KB |
testcase_14 | AC | 60 ms
27,776 KB |
testcase_15 | AC | 310 ms
141,568 KB |
testcase_16 | AC | 244 ms
107,648 KB |
testcase_17 | AC | 334 ms
148,096 KB |
testcase_18 | AC | 822 ms
148,736 KB |
testcase_19 | AC | 245 ms
103,680 KB |
testcase_20 | AC | 302 ms
138,240 KB |
testcase_21 | AC | 353 ms
162,048 KB |
testcase_22 | AC | 277 ms
128,640 KB |
testcase_23 | AC | 346 ms
154,880 KB |
testcase_24 | AC | 347 ms
155,008 KB |
testcase_25 | AC | 360 ms
155,008 KB |
testcase_26 | AC | 353 ms
155,008 KB |
testcase_27 | AC | 356 ms
155,008 KB |
testcase_28 | AC | 355 ms
155,008 KB |
testcase_29 | AC | 356 ms
155,008 KB |
testcase_30 | AC | 353 ms
155,008 KB |
testcase_31 | AC | 344 ms
155,008 KB |
testcase_32 | AC | 344 ms
155,008 KB |
testcase_33 | AC | 324 ms
142,080 KB |
testcase_34 | AC | 324 ms
137,088 KB |
testcase_35 | AC | 368 ms
136,784 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 363 ms
162,048 KB |
testcase_38 | AC | 381 ms
161,920 KB |
testcase_39 | AC | 384 ms
161,920 KB |
testcase_40 | AC | 433 ms
199,424 KB |
testcase_41 | AC | 436 ms
199,296 KB |
testcase_42 | AC | 455 ms
199,424 KB |
testcase_43 | AC | 430 ms
199,424 KB |
testcase_44 | AC | 433 ms
199,424 KB |
testcase_45 | AC | 426 ms
195,456 KB |
testcase_46 | AC | 78 ms
38,784 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::*; #[allow(dead_code)] fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn get_word() -> String { let mut stdin = std::io::stdin(); 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.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = std::string::String::from_utf8(buf).unwrap(); return ret; } } } fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() } #[allow(dead_code)] fn get<T: std::str::FromStr>() -> T { parse(&get_word()) } fn main() { let n: usize = get(); let x: i64 = get(); let a: Vec<i64> = (0 .. n).map(|_| get()).collect(); const THRESHOLD: i64 = 20000; let giants: Vec<(i64, usize)> = (0 .. n).map(|i| (a[i], i)).filter(|&(x, _)| x >= THRESHOLD).collect(); let babies: Vec<(usize, usize)> = (0 .. n).map(|i| (a[i], i)).filter(|&(x, _)| x < THRESHOLD) .map(|(x, y)| (x as usize, y)).collect(); let m = giants.len(); let p = babies.len(); // process giants assert!(m <= 23); // 20000^24 > 10^10000 let mut tbl = vec![-1_i64; 1 << m]; for bits in 0 .. (1 << m) { let mut tmp = 0; for i in 0 .. m { if (bits & (1 << i)) != 0 { tmp += giants[i].0; } } tbl[bits] = tmp; } // process babies let maxw = p * THRESHOLD as usize + 1; let mut dp = vec![vec![false; maxw]; p + 1]; dp[0][0] = true; for i in 0 .. p { for j in 0 .. maxw { let mut res = dp[i][j]; if j >= babies[i].0 { res |= dp[i][j - babies[i].0]; } dp[i + 1][j] = res; } } let mut giants_ans = None; let mut babies_ans = 0; for bits in 0 .. (1 << m) { let diff = x - tbl[bits]; if 0 <= diff && diff < maxw as i64 && dp[p][diff as usize] { giants_ans = Some(bits); babies_ans = diff as usize; break; } } match giants_ans { None => println!("No"), Some(gg) => { let mut ans = vec![false; n]; for i in 0 .. m { if (gg & (1 << i)) != 0 { ans[giants[i].1] = true; } } // Subset recovery let mut rem = babies_ans; for i in (0 .. p).rev() { let cur = babies[i].0; if rem >= cur && dp[i][rem - cur] { rem -= cur; ans[babies[i].1] = true; } } assert_eq!(rem, 0); for i in 0 .. n { print!("{}", if ans[i] { "o" } else { "x" }); } println!(""); } } }