Submission #3230337


Source Code Expand

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

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

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

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

pub 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
}

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);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let n: usize = read();
    let mut other_shops = vec![];
    for _i in 0..n {
        let o: Vec<usize> = readnc();
        let mut sum = 0;
        for j in 0..10 {
            if o[j] == 1 {
                sum |= 1<<j;
            }
        }
        other_shops.push(sum);
    }

    let mut count_table: Vec<Vec<i32>> = vec![];
    for _i in 0..n {
        count_table.push(readnc())
    }

    let mut ans = -1e9 as i32;
    for p in 1..(1<<10) {
        let mut total_profit = 0;
        for i in 0..n {
            let cnt = ((p & other_shops[i]) as usize).count_ones() as usize;
            total_profit += count_table[i][cnt];
        }
        ans = max(ans, total_profit);
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task C - Shopping Street
User hamadu
Language Rust (1.15.1)
Score 300
Code Size 2108 Byte
Status AC
Exec Time 2 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 4352 KB
02.txt AC 2 ms 4352 KB
03.txt AC 2 ms 4352 KB
04.txt AC 2 ms 4352 KB
05.txt AC 2 ms 4352 KB
06.txt AC 2 ms 4352 KB
07.txt AC 2 ms 4352 KB
08.txt AC 2 ms 4352 KB
09.txt AC 2 ms 4352 KB
10.txt AC 2 ms 4352 KB
11.txt AC 2 ms 4352 KB
12.txt AC 2 ms 4352 KB
13.txt AC 2 ms 4352 KB
14.txt AC 2 ms 4352 KB
15.txt AC 2 ms 4352 KB
16.txt AC 2 ms 4352 KB
sample_01.txt AC 2 ms 4352 KB
sample_02.txt AC 2 ms 4352 KB
sample_03.txt AC 2 ms 4352 KB