結果

問題 No.288 貯金箱の仕事
ユーザー koba-e964koba-e964
提出日時 2017-01-10 23:03:13
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 2,036 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 144,208 KB
実行使用メモリ 811,780 KB
最終ジャッジ日時 2023-08-22 22:23:13
合計ジャッジ時間 5,952 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,224 KB
testcase_01 AC 6 ms
8,756 KB
testcase_02 AC 9 ms
11,172 KB
testcase_03 AC 5 ms
6,616 KB
testcase_04 AC 10 ms
11,148 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 35 ms
39,244 KB
testcase_09 RE -
testcase_10 AC 94 ms
104,848 KB
testcase_11 RE -
testcase_12 AC 84 ms
93,168 KB
testcase_13 RE -
testcase_14 AC 81 ms
90,784 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 65 ms
72,048 KB
testcase_18 RE -
testcase_19 AC 57 ms
65,288 KB
testcase_20 AC 36 ms
41,760 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 -- -
権限があれば一括ダウンロードができます

ソースコード

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()) }

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 });
}
0