結果
問題 | No.288 貯金箱の仕事 |
ユーザー | koba-e964 |
提出日時 | 2017-01-10 23:05:31 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,058 bytes |
コンパイル時間 | 15,187 ms |
コンパイル使用メモリ | 376,312 KB |
実行使用メモリ | 492,928 KB |
最終ジャッジ日時 | 2024-05-10 03:59:05 |
合計ジャッジ時間 | 24,841 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
8,832 KB |
testcase_01 | WA | - |
testcase_02 | AC | 6 ms
5,888 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 6 ms
5,760 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 21 ms
17,408 KB |
testcase_09 | RE | - |
testcase_10 | AC | 54 ms
44,928 KB |
testcase_11 | RE | - |
testcase_12 | AC | 48 ms
40,064 KB |
testcase_13 | RE | - |
testcase_14 | AC | 46 ms
38,912 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 37 ms
31,232 KB |
testcase_18 | RE | - |
testcase_19 | AC | 33 ms
28,160 KB |
testcase_20 | AC | 20 ms
18,560 KB |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 4 ms
5,376 KB |
testcase_26 | AC | 5 ms
5,376 KB |
testcase_27 | AC | 5 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | AC | 362 ms
288,000 KB |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | AC | 229 ms
181,248 KB |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | AC | 5 ms
5,760 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()) } const INF: i64 = 1 << 60; fn solve(a: &[i64], v: i64) -> i64 { let n = a.len(); const W: usize = 250000; let mut dp: Vec<Vec<i32>> = vec![vec![0x3fff_ffff; W]; n + 1]; dp[0][0] = 0; for i in 0 .. n { let cur = a[i] as usize; for j in 0 .. W { let mut mi = dp[i][j]; if j >= cur { mi = min(mi, dp[i + 1][j - cur] + 1); } dp[i + 1][j] = mi; } } if v < W as i64 { return dp[n][v as usize] as i64; } let biggest = a[n - 1] as i64; let diff = (v + 1 - W as i64 + biggest - 1) / biggest * biggest; assert!(v - biggest < W as i64); return dp[n][(v - biggest) as usize] as i64 + diff / biggest; } fn main() { let n: usize = get(); let m: i64 = get(); let a: Vec<i64> = (0 .. n).map(|_| get()).collect(); let k: Vec<i64> = (0 .. n).map(|_| get()).collect(); let mut diff: i64 = 0; for i in 0 .. n { diff += a[i] * k[i]; } diff -= m; let result = solve(&a, diff); println!("{}", if result == INF { -1 } else { result }); }