Submission #1233344
Source Code Expand
use std::io; use std::io::{Read, BufReader}; use std::cmp; fn next_token<R: Read>(reader: &mut R) -> Vec<u8> { let mut buf: [u8; 1] = [0]; let mut read_chars = false; let mut ret: Vec<u8> = vec![]; loop { if reader.read(&mut buf).unwrap() == 0 { break; } else { if buf[0] == '\r' as u8 || buf[0] == '\n' as u8 || buf[0] == ' ' as u8 { if read_chars { break; } } else { read_chars = true; ret.push(buf[0]); } } }; ret } fn next_i64<R: Read>(reader: &mut R) -> i64 { let token = next_token(reader); let mut ret: i64 = 0; let mut sgn = false; for c in token { if '0' as u8 <= c && c <= '9' as u8 { ret = ret * 10 + (c - ('0' as u8)) as i64; } else if '-' as u8 == c { sgn = true; } }; ret * if sgn { -1 } else { 1 } } fn next_i32<R: Read>(reader: &mut R) -> i32 { next_i64(reader) as i32 } fn update(dp: &mut [bool], v: i32) { let mut i = dp.len() as i32 - 1 - v; while i >= 0 { if dp[i as usize] { dp[(i + v) as usize] = true } i -= 1; } } fn solve(k: i32, cards: &[i32], dp: [bool; 5050]) -> i32 { if cards.len() == 1 { for i in cmp::max(0, k - cards[0])..k { if dp[i as usize] { return 0 } } 1 } else { let thresh = cards.len() / 2; let mut ret = 0; { let mut dp2 = dp; for i in thresh..cards.len() { update(&mut dp2, cards[i as usize]); } ret += solve(k, &cards[0..thresh], dp2); } { let mut dp2 = dp; for i in 0..thresh { update(&mut dp2, cards[i as usize]); } ret += solve(k, &cards[thresh..cards.len()], dp2); } ret } } fn main() { let buf = &mut BufReader::new(io::stdin()); let n = next_i32(buf); let k = next_i32(buf); let mut cards: [i32; 5050] = [-1; 5050]; for i in 0..n { cards[i as usize] = next_i32(buf); } let mut dp = [false; 5050]; dp[0] = true; println!("{}", solve(k, &cards[0..(n as usize)], dp)); }
Submission Info
Submission Time | |
---|---|
Task | D - No Need |
User | semiexp |
Language | Rust (1.15.1) |
Score | 600 |
Code Size | 2425 Byte |
Status | AC |
Exec Time | 402 ms |
Memory | 4604 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 300 / 300 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
Subtask | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 2 ms | 4352 KB |
0_001.txt | AC | 2 ms | 4352 KB |
0_002.txt | AC | 2 ms | 4352 KB |
1_003.txt | AC | 2 ms | 4352 KB |
1_004.txt | AC | 2 ms | 4352 KB |
1_005.txt | AC | 2 ms | 4352 KB |
1_006.txt | AC | 2 ms | 4352 KB |
1_007.txt | AC | 2 ms | 4352 KB |
1_008.txt | AC | 21 ms | 4476 KB |
1_009.txt | AC | 20 ms | 4476 KB |
1_010.txt | AC | 3 ms | 4476 KB |
1_011.txt | AC | 3 ms | 4476 KB |
1_012.txt | AC | 19 ms | 4476 KB |
1_013.txt | AC | 20 ms | 4476 KB |
1_014.txt | AC | 25 ms | 4476 KB |
1_015.txt | AC | 25 ms | 4476 KB |
1_016.txt | AC | 2 ms | 4352 KB |
1_017.txt | AC | 2 ms | 4352 KB |
1_018.txt | AC | 2 ms | 4352 KB |
1_019.txt | AC | 22 ms | 4476 KB |
1_020.txt | AC | 22 ms | 4476 KB |
1_021.txt | AC | 25 ms | 4476 KB |
1_022.txt | AC | 8 ms | 4476 KB |
1_023.txt | AC | 6 ms | 4476 KB |
1_024.txt | AC | 24 ms | 4476 KB |
1_025.txt | AC | 24 ms | 4476 KB |
2_026.txt | AC | 2 ms | 4352 KB |
2_027.txt | AC | 3 ms | 4476 KB |
2_028.txt | AC | 3 ms | 4476 KB |
2_029.txt | AC | 402 ms | 4476 KB |
2_030.txt | AC | 402 ms | 4476 KB |
2_031.txt | AC | 9 ms | 4476 KB |
2_032.txt | AC | 9 ms | 4476 KB |
2_033.txt | AC | 13 ms | 4604 KB |
2_034.txt | AC | 13 ms | 4476 KB |
2_035.txt | AC | 214 ms | 4476 KB |
2_036.txt | AC | 215 ms | 4476 KB |
2_037.txt | AC | 2 ms | 4352 KB |
2_038.txt | AC | 2 ms | 4352 KB |
2_039.txt | AC | 3 ms | 4352 KB |
2_040.txt | AC | 14 ms | 4476 KB |
2_041.txt | AC | 310 ms | 4476 KB |
2_042.txt | AC | 255 ms | 4604 KB |
2_043.txt | AC | 132 ms | 4476 KB |
2_044.txt | AC | 199 ms | 4476 KB |
2_045.txt | AC | 204 ms | 4476 KB |
2_046.txt | AC | 187 ms | 4476 KB |
2_047.txt | AC | 201 ms | 4476 KB |
2_048.txt | AC | 208 ms | 4604 KB |
2_049.txt | AC | 168 ms | 4476 KB |
2_050.txt | AC | 144 ms | 4476 KB |