結果
問題 | No.506 限られたジャパリまん |
ユーザー | cympfh |
提出日時 | 2017-05-21 15:26:52 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 3,899 bytes |
コンパイル時間 | 16,001 ms |
コンパイル使用メモリ | 378,652 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 04:18:08 |
合計ジャッジ時間 | 16,332 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 7 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 6 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 6 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
warning: unused macro definition: `trace` --> src/main.rs:7:14 | 7 | macro_rules! trace { | ^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `swap` --> src/main.rs:12:14 | 12 | macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } | ^^^^
ソースコード
#![allow(unused_imports)] use std::io::{ self, Write }; use std::str::FromStr; use std::cmp::{ min, max }; use std::collections::{ BinaryHeap, VecDeque }; macro_rules! trace { ($var:expr) => ({ let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var); }) } macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } const M: i64 = 1000000007; struct Combination { n: usize, m: usize, ar: Vec<usize> } impl Combination { fn new(n: usize, m: usize) -> Combination { let mut ar = vec![0; m]; for i in 0..m { ar[i] = m - i - 1 } Combination { n: n, m: m, ar: ar } } } impl Iterator for Combination { type Item = Vec<usize>; fn next(&mut self) -> Option<Vec<usize>> { if self.m == 0 { if self.n == 0 { return None } else { self.n = 0; return Some(vec![]); } } if self.ar[self.m-1] > self.n - self.m { return None } let r = self.ar.clone(); self.ar[0] += 1; let mut c = 0; for i in 0..self.m-1 { if self.ar[i] >= self.n - i { self.ar[i + 1] += 1; c = i + 1; } else { break; } } for i in (0..c).rev() { self.ar[i] = self.ar[i+1] + 1; } return Some(r); } } fn main() { let mut sc = Scanner::new(); let h: usize = sc.cin(); let w: usize = sc.cin(); let k: usize = sc.cin(); let p: usize = sc.cin(); let mut f = vec![vec![false; w + 1]; h + 1]; let mut blocks = vec![]; for _ in 0..k { let x: usize = sc.cin(); let y: usize = sc.cin(); let name: String = sc.cin(); blocks.push((x, y, name)); f[x][y] = true; } let mut ans: i64 = 0; let mut opt_indices = vec![]; let mut memo = vec![vec![0; w + 1]; h + 1]; for ar in Combination::new(k, p) { for &i in ar.iter() { let (x, y, _) = blocks[i]; f[x][y] = false; } for i in 0..(h + 1) { for j in 0..(w + 1) { if f[i][j] { memo[i][j] = 0; } else if i == 0 && j == 0 { memo[0][0] = 1; } else if i == 0 { memo[0][j] = memo[0][j - 1]; } else if j == 0 { memo[i][0] = memo[i - 1][0]; } else { memo[i][j] = memo[i - 1][j] + memo[i][j - 1]; } } } if ans < memo[h][w] { ans = memo[h][w]; opt_indices = ar.clone(); } for &i in ar.iter() { let (x, y, _) = blocks[i]; f[x][y] = true; } } println!("{}", ans % M); opt_indices.sort(); for &i in opt_indices.iter() { println!("{}", blocks[i].2); } } #[allow(dead_code)] struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } } fn reserve(&mut self) { while self.buffer.len() == 0 { let mut line = String::new(); let _ = self.stdin.read_line(&mut line); for w in line.split_whitespace() { self.buffer.push_back(String::from(w)); } } } fn cin<T: FromStr>(&mut self) -> T { self.reserve(); match self.buffer.pop_front().unwrap().parse::<T>() { Ok(a) => a, Err(_) => panic!("parse err") } } fn get_char(&mut self) -> char { self.reserve(); let head = self.buffer[0].chars().nth(0).unwrap(); let tail = String::from( &self.buffer[0][1..] ); if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); } head } }