結果

問題 No.288 貯金箱の仕事
ユーザー koba-e964koba-e964
提出日時 2017-01-10 23:05:31
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,058 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 144,804 KB
実行使用メモリ 492,984 KB
最終ジャッジ日時 2023-08-22 22:23:38
合計ジャッジ時間 14,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,792 KB
testcase_01 WA -
testcase_02 AC 6 ms
5,896 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 5 ms
5,900 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 20 ms
17,516 KB
testcase_09 RE -
testcase_10 AC 54 ms
44,964 KB
testcase_11 RE -
testcase_12 AC 48 ms
40,204 KB
testcase_13 RE -
testcase_14 AC 46 ms
39,152 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 37 ms
31,192 KB
testcase_18 RE -
testcase_19 AC 33 ms
28,328 KB
testcase_20 AC 21 ms
18,576 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 4 ms
4,788 KB
testcase_26 AC 4 ms
4,796 KB
testcase_27 AC 4 ms
4,772 KB
testcase_28 AC 4 ms
4,860 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 359 ms
288,028 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 226 ms
181,188 KB
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 6 ms
5,848 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()) }

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