結果

問題 No.288 貯金箱の仕事
ユーザー koba-e964koba-e964
提出日時 2017-01-10 23:11:40
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 2,201 bytes
コンパイル時間 23,772 ms
コンパイル使用メモリ 405,716 KB
実行使用メモリ 492,800 KB
最終ジャッジ日時 2024-12-18 01:03:19
合計ジャッジ時間 24,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,576 KB
testcase_01 AC 4 ms
6,820 KB
testcase_02 AC 5 ms
6,816 KB
testcase_03 AC 3 ms
6,816 KB
testcase_04 AC 5 ms
6,816 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 63 ms
51,840 KB
testcase_08 AC 20 ms
17,536 KB
testcase_09 AC 49 ms
41,088 KB
testcase_10 AC 55 ms
44,800 KB
testcase_11 AC 24 ms
20,352 KB
testcase_12 AC 49 ms
39,936 KB
testcase_13 AC 39 ms
33,152 KB
testcase_14 AC 47 ms
38,912 KB
testcase_15 AC 59 ms
47,872 KB
testcase_16 AC 52 ms
41,984 KB
testcase_17 AC 37 ms
31,104 KB
testcase_18 AC 27 ms
22,272 KB
testcase_19 AC 34 ms
28,288 KB
testcase_20 AC 21 ms
18,560 KB
testcase_21 AC 24 ms
20,480 KB
testcase_22 AC 49 ms
40,064 KB
testcase_23 AC 643 ms
492,800 KB
testcase_24 AC 301 ms
247,808 KB
testcase_25 AC 5 ms
6,816 KB
testcase_26 AC 3 ms
6,820 KB
testcase_27 AC 4 ms
5,248 KB
testcase_28 AC 4 ms
5,248 KB
testcase_29 AC 3 ms
5,248 KB
testcase_30 AC 154 ms
127,360 KB
testcase_31 AC 154 ms
127,360 KB
testcase_32 AC 303 ms
249,856 KB
testcase_33 AC 303 ms
249,728 KB
testcase_34 AC 461 ms
372,352 KB
testcase_35 AC 465 ms
372,224 KB
testcase_36 AC 617 ms
492,800 KB
testcase_37 AC 173 ms
141,056 KB
testcase_38 AC 428 ms
340,992 KB
testcase_39 AC 206 ms
164,608 KB
testcase_40 AC 210 ms
169,472 KB
testcase_41 AC 593 ms
471,296 KB
testcase_42 AC 513 ms
409,600 KB
testcase_43 AC 354 ms
288,000 KB
testcase_44 AC 245 ms
201,728 KB
testcase_45 AC 465 ms
378,240 KB
testcase_46 AC 516 ms
414,464 KB
testcase_47 AC 341 ms
274,304 KB
testcase_48 AC 376 ms
299,648 KB
testcase_49 AC 223 ms
181,248 KB
testcase_50 AC 291 ms
237,056 KB
testcase_51 AC 212 ms
171,392 KB
testcase_52 AC 303 ms
242,944 KB
testcase_53 AC 397 ms
316,416 KB
testcase_54 AC 271 ms
219,520 KB
testcase_55 AC 5 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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 solve(a: &[i64], v: i64) -> Option<i64> {
    let n = a.len();
    const W: usize = 250000;
    const INF: i32 = 0x3fff_ffff;
    let mut dp: Vec<Vec<i32>> = 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 {
        let tmp = dp[n][v as usize];
        if tmp >= INF {
            return None;
        }
        return Some(tmp as i64);
    }
    let biggest = a[n - 1] as i64;
    let diff = (v + 1 - W as i64 + biggest - 1) / biggest * biggest;
    assert!(v - diff < W as i64);
    let tmp = dp[n][(v - diff) as usize];
    if tmp >= INF {
        return None;
    }
    return Some(tmp 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!("{}", result.unwrap_or(-1));
}
0