Submission #1627924


Source Code Expand

Copy
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, avg): (usize, usize) = read();
    let a: Vec<i32> = readnc();
    let max = n * 50 + 10;

    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![0; max]; n+1]; n+1];
    dp[0][0][0] = 1;

    for i in 0..n {
        for j in 0..n {
            for s in 0..max {
                let base = dp[i][j][s];
                if base == 0 {
                    continue
                }
                dp[i+1][j][s] += base;
                dp[i+1][j+1][s + a[i] as usize] += base;
            }
        }
    }

    let mut ans = 0;
    for j in 1..n+1 {
        ans += dp[n][j][j*avg as usize];
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task C - Tak and Cards
User hamadu
Language Rust (1.15.1)
Score 300
Code Size 1971 Byte
Status AC
Exec Time 42 ms
Memory 67836 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 4
AC × 12
AC × 24
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt
Case Name Status Exec Time Memory
example_01.txt AC 2 ms 4352 KB
example_02.txt AC 2 ms 4352 KB
example_03.txt AC 2 ms 4352 KB
example_04.txt AC 13 ms 20732 KB
subtask1_01.txt AC 3 ms 6396 KB
subtask1_02.txt AC 3 ms 6396 KB
subtask1_03.txt AC 3 ms 6396 KB
subtask1_04.txt AC 3 ms 6396 KB
subtask1_05.txt AC 3 ms 6396 KB
subtask1_06.txt AC 2 ms 4352 KB
subtask1_07.txt AC 2 ms 4352 KB
subtask1_08.txt AC 3 ms 6396 KB
subtask1_09.txt AC 3 ms 4352 KB
subtask2_01.txt AC 42 ms 67836 KB
subtask2_02.txt AC 42 ms 67836 KB
subtask2_03.txt AC 40 ms 65788 KB
subtask2_04.txt AC 41 ms 67836 KB
subtask2_05.txt AC 42 ms 67836 KB
subtask2_06.txt AC 41 ms 67836 KB
subtask2_07.txt AC 42 ms 67836 KB
subtask2_08.txt AC 13 ms 20732 KB
subtask2_09.txt AC 13 ms 20732 KB
subtask2_10.txt AC 28 ms 47356 KB
subtask2_11.txt AC 30 ms 51452 KB