提出 #67755123


ソースコード 拡げる

use std::cmp::max;
use proconio::*;

pub fn main() {
  input! {
    mut n: usize,
    m: usize,
    a: [(usize, usize); m]
  }
  let mut best = vec![0; 301];
  for (x, y) in a {
    best[x] = max(best[x], y);
  }
  let mut dp = vec![0; 2000001];
  for i in 0..dp.len() {
    dp[i] = i;
    for (x, y) in best.iter().enumerate() {
      if i >= x {
        dp[i] = max(dp[i], x + dp[i - x + y]);
      }
    }
  }
  let mut bestx = 0;
  let mut besty = 0;
  for (x, &y) in best.iter().enumerate() {
    if y != 0 && (bestx == 0 || bestx * (x - y) <= x * (bestx - besty)) {
      bestx = x;
      besty = y;
    }
  }
  let mut add = 0;
  if n >= dp.len() {
    let c = 1 + (n - dp.len()) / (bestx - besty);
    add = bestx * c;
    n -= c * (bestx - besty);
  }
  println!("{}", dp[n] + add);
}

提出情報

提出日時
問題 G - Get Many Cola
ユーザ BigBag
言語 Rust (rustc 1.70.0)
得点 575
コード長 830 Byte
結果 AC
実行時間 573 ms
メモリ 19176 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 575 / 575
結果
AC × 3
AC × 40
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 02_random2_20.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 563 ms 17476 KiB
00_sample_01.txt AC 563 ms 17476 KiB
00_sample_02.txt AC 564 ms 17440 KiB
01_random_00.txt AC 571 ms 18944 KiB
01_random_01.txt AC 570 ms 18704 KiB
01_random_02.txt AC 568 ms 18444 KiB
01_random_03.txt AC 570 ms 18696 KiB
01_random_04.txt AC 570 ms 18792 KiB
02_random2_00.txt AC 571 ms 19104 KiB
02_random2_01.txt AC 572 ms 18824 KiB
02_random2_02.txt AC 571 ms 18972 KiB
02_random2_03.txt AC 571 ms 18912 KiB
02_random2_04.txt AC 571 ms 18940 KiB
02_random2_05.txt AC 571 ms 18964 KiB
02_random2_06.txt AC 571 ms 18948 KiB
02_random2_07.txt AC 571 ms 19060 KiB
02_random2_08.txt AC 571 ms 18968 KiB
02_random2_09.txt AC 571 ms 18824 KiB
02_random2_10.txt AC 572 ms 19044 KiB
02_random2_11.txt AC 571 ms 18924 KiB
02_random2_12.txt AC 571 ms 19036 KiB
02_random2_13.txt AC 572 ms 19016 KiB
02_random2_14.txt AC 572 ms 18984 KiB
02_random2_15.txt AC 572 ms 18916 KiB
02_random2_16.txt AC 572 ms 19056 KiB
02_random2_17.txt AC 572 ms 18952 KiB
02_random2_18.txt AC 572 ms 18828 KiB
02_random2_19.txt AC 571 ms 18980 KiB
02_random2_20.txt AC 571 ms 18980 KiB
03_random3_00.txt AC 571 ms 18936 KiB
03_random3_01.txt AC 573 ms 18960 KiB
03_random3_02.txt AC 571 ms 18920 KiB
03_random3_03.txt AC 572 ms 18828 KiB
03_random3_04.txt AC 571 ms 18896 KiB
03_random3_05.txt AC 571 ms 18844 KiB
04_handmade_00.txt AC 569 ms 18360 KiB
04_handmade_01.txt AC 570 ms 18372 KiB
04_handmade_02.txt AC 564 ms 17344 KiB
04_handmade_03.txt AC 563 ms 17380 KiB
04_handmade_04.txt AC 571 ms 19176 KiB