結果

問題 No.1238 選抜クラス
ユーザー 👑 箱
提出日時 2020-09-25 22:23:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 892 ms / 2,000 ms
コード長 3,249 bytes
コンパイル時間 2,945 ms
コンパイル使用メモリ 159,004 KB
実行使用メモリ 17,776 KB
最終ジャッジ日時 2023-09-10 15:38:33
合計ジャッジ時間 17,498 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 886 ms
17,684 KB
testcase_18 AC 814 ms
16,748 KB
testcase_19 AC 835 ms
17,164 KB
testcase_20 AC 758 ms
16,164 KB
testcase_21 AC 688 ms
15,400 KB
testcase_22 AC 892 ms
17,760 KB
testcase_23 AC 886 ms
17,760 KB
testcase_24 AC 887 ms
17,768 KB
testcase_25 AC 881 ms
17,776 KB
testcase_26 AC 878 ms
17,776 KB
testcase_27 AC 881 ms
17,724 KB
testcase_28 AC 876 ms
17,764 KB
testcase_29 AC 825 ms
17,108 KB
testcase_30 AC 22 ms
4,380 KB
testcase_31 AC 137 ms
6,660 KB
testcase_32 AC 384 ms
11,312 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 534 ms
13,456 KB
testcase_35 AC 44 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 27 ms
4,380 KB
testcase_38 AC 740 ms
16,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `M` should have a snake case name
  --> Main.rs:92:9
   |
92 |     let M = 1000000007;
   |         ^ help: convert the identifier to snake case: `m`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::io::{stdout, BufReader, BufWriter, Read, Write};

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = Read::bytes(BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let out = stdout();
    let mut writer = BufWriter::new(out.lock());
    solve(&mut writer);
    writer.flush().unwrap();
}

fn solve<W: Write>(mut writer: W) {
    #[allow(unused_macros)]
    macro_rules! print {
        ($fmt:expr) => {
            write!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            write!(writer, $fmt, $($arg)*).unwrap()
        };
    }
    #[allow(unused_macros)]
    macro_rules! println {
        ($fmt:expr) => {
            writeln!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            writeln!(writer, $fmt, $($arg)*).unwrap()
        };
    }

    // Main Code
    input! {
        n: usize,
        a: usize,
        x: [usize; n]
    }
    let M = 1000000007;
    let size = 100 * n + 1;
    let mut dp = vec![vec![0 as usize; size]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        let mut newdp = vec![vec![0; size]; n + 1];
        for j in 0..=n {
            for k in 0..size {
                if j > 0 && k >= x[i] {
                    newdp[j][k] = dp[j][k] + dp[j - 1][k - x[i]];
                }
                else {
                    newdp[j][k] = dp[j][k];
                }
                newdp[j][k] %= M;
            }
        }
        dp = newdp;
    }
    let mut ans = 0 as usize;
    for i in 1..=n {
        if i * a >= size {
            break;
        }
        for b in i * a .. size {
            ans += dp[i][b];
            ans %= M;
        }
    }
    println!("{}", ans);
}
0