結果

問題 No.1947 質より種類数
ユーザー bqnbqn
提出日時 2022-05-22 19:34:12
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 7,958 bytes
コンパイル時間 12,532 ms
コンパイル使用メモリ 378,728 KB
実行使用メモリ 197,760 KB
最終ジャッジ日時 2024-09-20 12:49:34
合計ジャッジ時間 19,110 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 43 ms
5,376 KB
testcase_05 AC 44 ms
5,376 KB
testcase_06 AC 37 ms
5,376 KB
testcase_07 AC 48 ms
5,376 KB
testcase_08 AC 54 ms
5,376 KB
testcase_09 AC 44 ms
6,400 KB
testcase_10 AC 34 ms
5,376 KB
testcase_11 AC 76 ms
11,776 KB
testcase_12 AC 59 ms
8,960 KB
testcase_13 AC 28 ms
5,376 KB
testcase_14 AC 164 ms
56,576 KB
testcase_15 AC 94 ms
29,696 KB
testcase_16 AC 217 ms
81,792 KB
testcase_17 AC 264 ms
105,600 KB
testcase_18 AC 415 ms
187,392 KB
testcase_19 AC 372 ms
163,840 KB
testcase_20 AC 297 ms
123,264 KB
testcase_21 AC 338 ms
145,408 KB
testcase_22 AC 33 ms
10,112 KB
testcase_23 AC 186 ms
65,920 KB
testcase_24 AC 71 ms
5,376 KB
testcase_25 AC 58 ms
5,376 KB
testcase_26 AC 38 ms
5,376 KB
testcase_27 AC 65 ms
5,376 KB
testcase_28 AC 58 ms
5,376 KB
testcase_29 AC 391 ms
197,760 KB
testcase_30 AC 421 ms
197,760 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 68 ms
5,376 KB
testcase_34 AC 330 ms
197,760 KB
testcase_35 AC 268 ms
197,760 KB
testcase_36 AC 424 ms
197,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `input_inner`
  --> src/main.rs:89:14
   |
89 | macro_rules! input_inner {
   |              ^^^^^^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

warning: unused macro definition: `min`
   --> src/main.rs:238:15
    |
238 | macro_rules ! min { ( $x : expr ) => ( $x ) ; ( $x : expr , $ ( $xs : expr ) ,+ ) => { {  std :: cmp :: min ( $x , min! ( $ ( $xs ) ,+ ) ...
    |               ^^^

warning: unused macro definition: `chmin`
   --> src/main.rs:240:14
    |
240 | macro_rules! chmin {
    |              ^^^^^

warning: unused macro definition: `chadd`
   --> src/main.rs:264:14
    |
264 | macro_rules! chadd {
    |              ^^^^^

warning: unused macro definition: `chsub`
   --> src/main.rs:270:14
    |
270 | macro_rules! chsub {
    |              ^^^^^

warning: unused macro definition: `chmul`
   --> src/main.rs:275:14
    |
275 | macro_rules! chmul {
    |              ^^^^^

ソースコード

diff #

#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

type Vec2<T> = Vec<Vec<T>>;
type Vec3<T> = Vec<Vec<Vec<T>>>;

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_macros)]
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Rem, Sub};

trait SafeRangeContain {
    fn safe_contains(&self, x: i64) -> bool;
}

impl SafeRangeContain for std::ops::Range<usize> {
    fn safe_contains(&self, x: i64) -> bool {
        if x < 0 {
            return false;
        }
        return self.contains(&(x as usize));
    }
}

#[allow(dead_code)]
static INF_I64: i64 = i64::max_value() / 2;
#[allow(dead_code)]
static INF_I32: i32 = i32::max_value() / 2;
#[allow(dead_code)]
static INF_USIZE: usize = usize::max_value() / 2;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}
macro_rules ! max { ( $x : expr ) => ( $x ) ; ( $x : expr , $ ( $xs : expr ) ,+ ) => { {  std :: cmp :: max ( $x , max! ( $ ( $xs ) ,+ ) ) } } ; }
macro_rules ! min { ( $x : expr ) => ( $x ) ; ( $x : expr , $ ( $xs : expr ) ,+ ) => { {  std :: cmp :: min ( $x , min! ( $ ( $xs ) ,+ ) ) } } ; }

macro_rules! chmin {
    ($a:expr, $($b:expr),+) => {{
        let d = min!($($b),+);
        if $a > d {
            $a = d;
            true
        } else {
            false
        }
    }};
}

macro_rules! chmax {
    ($a:expr, $($b:expr),+) => {{
        let d = max!($($b),+);
        if $a < d {
            $a = d;
            true
        } else {
            false
        }
    }};
}

macro_rules! chadd {
    ($a:expr, $b:expr) => {{
        $a = $a + $b;
    }};
}

macro_rules! chsub {
    ($a:expr, $b:expr) => {{
        $a = $a - $b;
    }};
}
macro_rules! chmul {
    ($a:expr, $b:expr) => {{
        $a = $a * $b;
    }};
}

fn main() {
    solve();
}

fn solve() {
    let mut ans: u64 = 0;

    let (N, V, C) = get!(usize, usize, usize);
    let mut A = vec![];
    for _ in 0..N {
        A.push(get!(usize, usize));
    }
    let mut dp = vec![vec![0; V + 5]; N + 5];
    let mut f = vec![true; N];
    for i in 0..N {
        let (v, w) = A[i];
        for j in 0..N {
            if i == j {
                continue;
            }
            let (v2, w2) = A[j];
            if v == v2 {
                if w < w2 {
                    f[i] = false;
                    break;
                } else if i > j && w <= w2 {
                    f[i] = false;
                    break;
                }
            }
        }
    }
    mydbg!(f);

    for i in 0..N {
        for j in 0..=V {
            for k in 1.. {
                let (v, w) = A[i];
                let next = j + k * v;
                if next > V {
                    break;
                }

                let x = w * k + C;
                chmax!(dp[i + 1][next], dp[i][j] + x);
                if !f[i] {
                    break;
                }
            }
            chmax!(dp[i + 1][j], dp[i][j]);
        }
    }
    echo!(dp[N].iter().max().unwrap());
}
0