結果

問題 No.1495 パンの仕入れ
ユーザー akakimidoriakakimidori
提出日時 2021-03-31 14:05:02
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,393 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 158,904 KB
実行使用メモリ 9,808 KB
最終ジャッジ日時 2023-08-22 09:42:17
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 106 ms
9,776 KB
testcase_23 AC 101 ms
9,804 KB
testcase_24 AC 18 ms
6,968 KB
testcase_25 AC 18 ms
6,968 KB
testcase_26 AC 18 ms
6,988 KB
testcase_27 AC 17 ms
7,024 KB
testcase_28 AC 97 ms
9,808 KB
testcase_29 AC 92 ms
9,804 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 23 ms
9,132 KB
testcase_36 AC 24 ms
9,104 KB
testcase_37 AC 23 ms
9,140 KB
testcase_38 AC 23 ms
9,064 KB
testcase_39 AC 24 ms
9,032 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1 ms
4,380 KB
testcase_46 WA -
testcase_47 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `x`
  --> Main.rs:74:10
   |
74 |     let (x, y) = eval(ok);
   |          ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

const MAX_T: i64 = 100;
const MAX_N: i64 = 200_000;
const MAX_M: i64 = 200_000;
const MAX_K: i64 = 1_000_000_000;
const MAX_Y: i64 = 1_000_000_000;

fn read() -> Vec<(usize, i64, Vec<(usize, i64)>)> {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut next = |l: i64, r: i64| {
        let v = it.next().unwrap().parse::<i64>().unwrap();
        assert!(l <= v && v <= r);
        v
    };
    let t = next(1, MAX_T) as usize;
    let mut sum_n = 0;
    let mut sum_m = 0;
    let mut test = vec![];
    for _ in 0..t {
        let n = next(1, MAX_N - sum_n) as usize;
        let m = next(1, MAX_M - sum_m) as usize;
        let k = next(1, MAX_K);
        let mut p = vec![(0usize, 0i64); m];
        for p in p.iter_mut() {
            p.0 = (next(1, n as i64) - 1) as usize;
            p.1 = next(1, MAX_Y);
        }
        assert!(
            m.saturating_mul(k.max(p.iter().map(|p| p.1).max().unwrap()) as usize)
                <= 10usize.pow(18)
        );
        test.push((n, k, p));
        sum_n += n as i64;
        sum_m += m as i64;
    }
    test
}

fn solve(n: usize, k: i64, p: &[(usize, i64)]) -> i64 {
    let mut dp = vec![(0, 0, 0); n];
    for &(x, y) in p.iter() {
        let po = &mut dp[x];
        po.0 += y * y;
        po.1 -= 2 * y;
        po.2 += 1;
    }
    let eval = |m: i64| -> (i64, i64) {
        let mut cnt = 0;
        let mut cost = 0;
        for &(c, b, a) in dp.iter() {
            cost += c;
            if a > 0 {
                let x = ((m - (b - a)).div_euclid(2 * a)).max(0);
                cnt += x;
                cost += 2 * a * (x + 1) * x / 2 + (b - a) * x;
            } else if m >= 0 {
                cnt += k;
            }
        }
        (cnt, cost)
    };
    let mut ng = dp.iter().map(|&(_, b, a)| 2 * a + b - a - 1).min().unwrap();
    let mut ok = dp.iter().map(|&(_, b, a)| 2 * a * k + b - a).min().unwrap();
    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        if eval(mid).0 >= k {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    let (x, y) = eval(ok);
    let ans = y;
//    let ans = y - ok * (x - k);
    ans
}

fn main() {
    let test = read();
    for (n, k, p) in test {
        let ans = solve(n, k, &p);
        println!("{}", ans);
    }
}
0