結果
| 問題 | No.505 カードの数式2 |
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2023-04-14 15:56:28 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 991 bytes |
| 記録 | |
| コンパイル時間 | 8,279 ms |
| コンパイル使用メモリ | 191,028 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-26 10:05:50 |
| 合計ジャッジ時間 | 8,141 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 29 |
ソースコード
use std::{convert::TryFrom, io::stdin, iter::repeat_with, usize::MAX};
use itertools::Itertools;
fn main() {
let stdin = stdin();
let mut stdin = stdin.lines().map(Result::unwrap);
let n = stdin.next().unwrap().parse::<usize>().unwrap();
let ab = repeat_with(|| {
<[_; 2]>::try_from(
stdin
.next()
.unwrap()
.split_whitespace()
.map(|x| x.parse::<usize>().unwrap())
.collect::<Vec<_>>(),
)
.unwrap()
})
.take(n)
.collect::<Vec<_>>();
let lim = ab.iter().map(|&[x, _]| x).sum::<usize>() + 1;
let mut dp = vec![MAX; lim];
dp[0] = 0;
for &[x, y] in &ab {
let mut swp = dp.iter().map(|&x| x.saturating_add(y)).collect_vec();
for i in 0..lim - x {
swp[i + x] = swp[i + x].min(dp[i]);
}
dp = swp;
}
let ans = (0..lim).map(|i| i.max(dp[i])).min().unwrap();
println!("{}", ans);
}
ngtkana