結果
問題 | No.798 コレクション |
ユーザー |
![]() |
提出日時 | 2023-05-02 14:11:18 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 3,130 bytes |
コンパイル時間 | 12,921 ms |
コンパイル使用メモリ | 401,384 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 05:06:39 |
合計ジャッジ時間 | 12,748 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
use input::{input, input_array};use std::{cmp::Reverse, iter::repeat_with, usize::MAX};fn main() {let n = input::<usize>();let mut ab = repeat_with(|| input_array::<usize, 2>()).take(n).collect::<Vec<_>>();ab.sort_by_key(|&[_, b]| Reverse(b));let mut dp = vec![MAX; n + 1];dp[0] = 0;for (pos, &[a, b]) in ab.iter().enumerate() {for i in (0..=pos).rev() {change_min!(&mut dp[i + 1], dp[i] + a + b * i);}}let ans = dp[n - n / 3];println!("{}", ans);}// cmpmore {{{#[allow(dead_code)]mod cmpmore {pub fn change_min<T: PartialOrd>(lhs: &mut T, rhs: T) {if *lhs > rhs {*lhs = rhs;}}pub fn change_max<T: PartialOrd>(lhs: &mut T, rhs: T) {if *lhs < rhs {*lhs = rhs;}}#[macro_export]macro_rules! change_min {($lhs:expr, $rhs:expr) => {let rhs = $rhs;let lhs = $lhs;$crate::cmpmore::change_min(lhs, rhs);};}#[macro_export]macro_rules! change_max {($lhs:expr, $rhs:expr) => {let rhs = $rhs;let lhs = $lhs;$crate::cmpmore::change_max(lhs, rhs);};}pub trait CmpMore: PartialOrd + Sized {fn change_min(&mut self, rhs: Self) {change_min(self, rhs)}fn change_max(&mut self, rhs: Self) {change_max(self, rhs)}}impl<T: PartialOrd + Sized> CmpMore for T {}}// }}}// input {{{#[allow(dead_code)]mod input {use std::{cell::Cell,convert::TryFrom,io::{stdin, BufRead, BufReader, Lines, Stdin},str::FromStr,sync::{Mutex, Once},};type Server = Mutex<Lines<BufReader<Stdin>>>;static ONCE: Once = Once::new();pub struct Lazy(Cell<Option<Server>>);unsafe impl Sync for Lazy {}fn line() -> String {static SYNCER: Lazy = Lazy(Cell::new(None));ONCE.call_once(|| {SYNCER.0.set(Some(Mutex::new(BufReader::new(stdin()).lines())));});unsafe {(*SYNCER.0.as_ptr()).as_ref().unwrap().lock().unwrap().next().unwrap().unwrap()}}pub trait ForceFromStr: FromStr {fn force_from_str(s: &str) -> Self;}impl<T, E> ForceFromStr for TwhereT: FromStr<Err = E>,E: std::fmt::Debug,{fn force_from_str(s: &str) -> Self {s.parse().unwrap()}}pub fn input_array<T: ForceFromStr, const N: usize>() -> [T; N]whereT: std::fmt::Debug,{<[_; N]>::try_from(input_vec()).unwrap()}pub fn input_vec<T: ForceFromStr>() -> Vec<T> {line().split_whitespace().map(T::force_from_str).collect::<Vec<_>>()}pub fn input<T: ForceFromStr>() -> T {T::force_from_str(&line())}}// }}}