Submission #72562876
Source Code Expand
#![allow(non_snake_case, unused_imports, unused_macros)]
use std::{collections::BTreeSet, mem::needs_drop};
use ac_library::*;
use itertools::Itertools;
use proconio::{fastout, input};
use rustc_hash::FxHashSet;
macro_rules! debug {
($($a:expr),* $(,)*) => {
#[cfg(debug_assertions)]
eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
};
}
#[fastout]
fn main() {
input! {
n: usize, m: usize,
pv: [(usize, usize); n]
}
let mut dp = vec![vec![None::<usize>; m + 1]];
dp[0][0] = Some(0);
for (i, &(pi, vi)) in pv.iter().enumerate() {
let next_dp = (0..=m)
.map(|p| {
dp[i][p].max(
dp[i]
.get(p.wrapping_sub(pi))
.copied()
.flatten()
.map(|v| v + vi),
)
})
.collect_vec();
dp.push(next_dp);
}
// debug!(dp);
let mut must_buy = vec![false; n];
let mut may_buy = vec![false; n];
let maxarg_v = (0..=m).max_set_by_key(|&p| dp[n][p]);
let mut prices = FxHashSet::from_iter(maxarg_v);
for (i, &(pi, vi)) in pv.iter().enumerate().rev() {
// debug!(prices, i, pi, vi);
let mut next_prices = FxHashSet::default();
let mut may_not_buy = false;
for price in prices {
if price >= pi
&& let Some(v) = dp[i][price - pi]
&& v + vi == dp[i + 1][price].unwrap()
{
next_prices.insert(price - pi);
may_buy[i] = true;
}
if let Some(v) = dp[i][price]
&& v == dp[i + 1][price].unwrap()
{
next_prices.insert(price);
may_not_buy = true;
}
}
must_buy[i] = !may_not_buy;
prices = next_prices;
}
for i in 0..n {
if must_buy[i] {
print!("A");
} else if may_buy[i] {
print!("B");
} else {
print!("C")
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Must Buy |
| User | wasabiEater |
| Language | Rust (rustc 1.89.0) |
| Score | 0 |
| Code Size | 2187 Byte |
| Status | TLE |
| Exec Time | > 2500 ms |
| Memory | 787804 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 1 ms | 2088 KiB |
| example_01.txt | AC | 0 ms | 2112 KiB |
| hand_00.txt | AC | 322 ms | 786020 KiB |
| hand_01.txt | AC | 313 ms | 785952 KiB |
| hand_02.txt | AC | 354 ms | 785968 KiB |
| hand_03.txt | TLE | > 2500 ms | 787792 KiB |
| hand_04.txt | AC | 1760 ms | 786872 KiB |
| hand_05.txt | AC | 209 ms | 255196 KiB |
| hand_06.txt | AC | 335 ms | 786024 KiB |
| hand_07.txt | AC | 46 ms | 80100 KiB |
| hand_08.txt | AC | 320 ms | 785972 KiB |
| hand_09.txt | AC | 322 ms | 785972 KiB |
| hand_10.txt | TLE | > 2500 ms | 787804 KiB |
| hand_11.txt | AC | 315 ms | 786060 KiB |
| hand_12.txt | AC | 1 ms | 3448 KiB |
| hand_13.txt | AC | 1 ms | 2664 KiB |
| hand_14.txt | AC | 7 ms | 17528 KiB |
| hand_15.txt | AC | 322 ms | 785952 KiB |
| hand_16.txt | AC | 323 ms | 785948 KiB |
| hand_17.txt | AC | 407 ms | 786048 KiB |
| random_00.txt | AC | 329 ms | 782748 KiB |
| random_01.txt | AC | 327 ms | 777280 KiB |
| random_02.txt | AC | 328 ms | 778812 KiB |
| random_03.txt | AC | 18 ms | 43652 KiB |
| random_04.txt | AC | 15 ms | 36176 KiB |
| random_05.txt | AC | 92 ms | 222612 KiB |
| random_06.txt | AC | 76 ms | 179448 KiB |
| random_07.txt | AC | 172 ms | 405476 KiB |
| random_08.txt | AC | 165 ms | 378848 KiB |
| random_09.txt | AC | 318 ms | 751876 KiB |
| random_10.txt | AC | 331 ms | 783612 KiB |
| random_11.txt | AC | 330 ms | 781308 KiB |
| random_12.txt | AC | 329 ms | 780500 KiB |
| random_13.txt | AC | 340 ms | 784312 KiB |
| random_14.txt | AC | 341 ms | 785156 KiB |
| random_15.txt | AC | 640 ms | 781740 KiB |
| random_16.txt | AC | 328 ms | 775672 KiB |
| random_17.txt | AC | 337 ms | 774196 KiB |
| random_18.txt | AC | 585 ms | 781596 KiB |
| random_19.txt | AC | 722 ms | 784864 KiB |
| random_20.txt | AC | 714 ms | 775512 KiB |
| random_21.txt | AC | 424 ms | 777484 KiB |
| random_22.txt | AC | 391 ms | 774408 KiB |
| random_23.txt | AC | 318 ms | 780412 KiB |
| random_24.txt | AC | 318 ms | 785196 KiB |
| random_25.txt | AC | 322 ms | 779736 KiB |
| random_26.txt | AC | 328 ms | 775080 KiB |
| random_27.txt | AC | 448 ms | 775204 KiB |
| random_28.txt | AC | 342 ms | 771804 KiB |
| random_29.txt | AC | 341 ms | 784524 KiB |