Submission #34509607
Source Code Expand
Copy
use proconio::{input, marker::Chars};macro_rules! chmax {($max_v: expr, $v: expr) => {if $v > $max_v {$max_v = $v;true} else {false}};}macro_rules! chmin {($min_v: expr, $v: expr) => {if $v < $min_v {$min_v = $v;true} else {false}
use proconio::{input, marker::Chars}; macro_rules! chmax { ($max_v: expr, $v: expr) => { if $v > $max_v { $max_v = $v; true } else { false } }; } macro_rules! chmin { ($min_v: expr, $v: expr) => { if $v < $min_v { $min_v = $v; true } else { false } }; } fn main() { input! { h: usize, w: usize, a: [Chars; h], }; // let f = |b: &[Vec<i64>]| { // for i in 0..h { // for j in 0..w { // print!("{:3}", b[i][j]); // } // println!(); // } // println!(); // }; let mut b = vec![vec![0_i64; w]; h]; for i in 0..h { for j in 0..w { b[i][j] = match (a[i][j], (i + j) % 2 == 0) { ('+', true) => -1, ('+', false) => 1, ('-', true) => 1, ('-', false) => -1, _ => unreachable!(), }; } } b[0][0] = 0; let inf = h as i64 * w as i64 + 1; let mut dp = vec![vec![inf; w]; h]; dp[h - 1][w - 1] = b[h - 1][w - 1]; for i in (0..h).rev() { for j in (0..w).rev() { if i != 0 { if dp[i - 1][j] == inf { dp[i - 1][j] = dp[i][j] + b[i - 1][j]; } else if (i + j) % 2 == 0 { chmin!(dp[i - 1][j], dp[i][j] + b[i - 1][j]); } else { chmax!(dp[i - 1][j], dp[i][j] + b[i - 1][j]); } } if j != 0 { if dp[i][j - 1] == inf { dp[i][j - 1] = dp[i][j] + b[i][j - 1]; } else if (i + j) % 2 == 0 { chmin!(dp[i][j - 1], dp[i][j] + b[i][j - 1]); } else { chmax!(dp[i][j - 1], dp[i][j] + b[i][j - 1]); } } } } // f(&b); // f(&dp); let ans = if dp[0][0] == 0 { "Draw" } else if dp[0][0] > 0 { "Takahashi" } else { "Aoki" }; println!("{}", ans); }
Submission Info
Submission Time | |
---|---|
Task | D - Game in Momotetsu World |
User | bouzuya |
Language | Rust (1.42.0) |
Score | 400 |
Code Size | 2182 Byte |
Status | AC |
Exec Time | 125 ms |
Memory | 84384 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | extreme_00.txt, handmade_00.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
extreme_00.txt | AC | 96 ms | 84384 KB |
handmade_00.txt | AC | 1 ms | 2164 KB |
random_00.txt | AC | 117 ms | 84352 KB |
random_01.txt | AC | 114 ms | 84216 KB |
random_02.txt | AC | 125 ms | 84372 KB |
random_03.txt | AC | 109 ms | 84292 KB |
random_04.txt | AC | 9 ms | 4204 KB |
random_05.txt | AC | 1 ms | 2004 KB |
random_06.txt | AC | 2 ms | 2368 KB |
random_07.txt | AC | 4 ms | 4468 KB |
random_08.txt | AC | 76 ms | 47200 KB |
random_09.txt | AC | 26 ms | 11424 KB |
sample_01.txt | AC | 2 ms | 2084 KB |
sample_02.txt | AC | 2 ms | 2124 KB |
sample_03.txt | AC | 2 ms | 2064 KB |