Submission #2526919


Source Code Expand

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(l: usize, r: usize, h: usize) -> usize {
    (r - l + 1) * h
}
fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let mut field = vec![vec![]; h];
    for y in 0..h {
        field[y] = read::<String>().chars().collect::<Vec<char>>();
    }
    let mut ans = std::cmp::max(h, w);
    let mut heights = vec![vec![1; w]; h];
    for y in 0..h - 1 {
        for x in (0..w - 1).rev() {
            if (field[y][x] == field[y][x + 1]) == (field[y + 1][x] == field[y + 1][x + 1]) {
                heights[y][x] += heights[y][x + 1];
            }
        }
    }
    for x in 0..w - 1 {
        let mut stack = vec![(0, 0)];
        for y in 0..h {
            let mut py = y;
            let lh = heights[y][x];
            while stack.last().unwrap().1 > lh {
                py = stack.last().unwrap().0;
                let ph = stack.last().unwrap().1;
                ans = std::cmp::max(ans, calc(py, y, ph));
                stack.pop();
            }
            stack.push((py, lh));
        }
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task F - Flip and Rectangles
User cos
Language Rust (1.15.1)
Score 700
Code Size 1529 Byte
Status AC
Exec Time 190 ms
Memory 61692 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 2 ms 4352 KB
10.txt AC 168 ms 61692 KB
11.txt AC 83 ms 35068 KB
12.txt AC 156 ms 61692 KB
13.txt AC 156 ms 61692 KB
14.txt AC 155 ms 61692 KB
15.txt AC 163 ms 61692 KB
16.txt AC 155 ms 61692 KB
17.txt AC 156 ms 61692 KB
18.txt AC 171 ms 61692 KB
19.txt AC 162 ms 61692 KB
2.txt AC 2 ms 4352 KB
20.txt AC 160 ms 61692 KB
21.txt AC 165 ms 61692 KB
22.txt AC 160 ms 61692 KB
23.txt AC 156 ms 61692 KB
24.txt AC 160 ms 61692 KB
25.txt AC 160 ms 61692 KB
26.txt AC 173 ms 61692 KB
27.txt AC 171 ms 61692 KB
28.txt AC 174 ms 61692 KB
29.txt AC 148 ms 61692 KB
3.txt AC 190 ms 61692 KB
30.txt AC 154 ms 61692 KB
31.txt AC 155 ms 61692 KB
32.txt AC 158 ms 61692 KB
33.txt AC 158 ms 61692 KB
34.txt AC 158 ms 61692 KB
4.txt AC 190 ms 61692 KB
5.txt AC 2 ms 4352 KB
6.txt AC 2 ms 4352 KB
7.txt AC 176 ms 61692 KB
8.txt AC 177 ms 61692 KB
9.txt AC 167 ms 61692 KB
sample1.txt AC 2 ms 4352 KB
sample2.txt AC 2 ms 4352 KB
sample3.txt AC 2 ms 4352 KB