結果
問題 | No.288 貯金箱の仕事 |
ユーザー | koba-e964 |
提出日時 | 2017-01-10 23:03:13 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,036 bytes |
コンパイル時間 | 15,400 ms |
コンパイル使用メモリ | 389,608 KB |
実行使用メモリ | 793,256 KB |
最終ジャッジ日時 | 2024-05-10 03:58:32 |
合計ジャッジ時間 | 16,842 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
18,220 KB |
testcase_01 | AC | 7 ms
8,704 KB |
testcase_02 | AC | 9 ms
11,160 KB |
testcase_03 | AC | 4 ms
6,940 KB |
testcase_04 | AC | 9 ms
11,136 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 36 ms
39,328 KB |
testcase_09 | RE | - |
testcase_10 | AC | 103 ms
104,936 KB |
testcase_11 | RE | - |
testcase_12 | AC | 88 ms
93,160 KB |
testcase_13 | RE | - |
testcase_14 | AC | 87 ms
90,948 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 67 ms
72,188 KB |
testcase_18 | RE | - |
testcase_19 | AC | 61 ms
65,136 KB |
testcase_20 | AC | 40 ms
41,656 KB |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | MLE | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
ソースコード
#[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 = 300000; let mut dp: Vec<Vec<i64>> = vec![vec![INF; 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]; } 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] + 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 }); }