結果

問題 No.2456 Stamp Art
ユーザー koba-e964koba-e964
提出日時 2023-09-03 03:46:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 694 ms / 5,000 ms
コード長 2,541 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 156,100 KB
実行使用メモリ 49,172 KB
最終ジャッジ日時 2023-09-03 03:47:02
合計ジャッジ時間 11,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 471 ms
49,128 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 544 ms
49,168 KB
testcase_07 AC 577 ms
49,168 KB
testcase_08 AC 533 ms
49,172 KB
testcase_09 AC 580 ms
49,160 KB
testcase_10 AC 662 ms
49,140 KB
testcase_11 AC 525 ms
49,160 KB
testcase_12 AC 583 ms
49,160 KB
testcase_13 AC 684 ms
49,088 KB
testcase_14 AC 694 ms
49,100 KB
testcase_15 AC 477 ms
49,164 KB
testcase_16 AC 239 ms
25,680 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 319 ms
33,352 KB
testcase_20 AC 607 ms
49,164 KB
testcase_21 AC 573 ms
44,652 KB
testcase_22 AC 607 ms
49,164 KB
testcase_23 AC 18 ms
4,508 KB
testcase_24 AC 46 ms
5,880 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        h: usize, w: usize,
        s: [chars; h],
    }
    let mut acc = vec![vec![0; w + 1]; h + 1];
    for i in 0..h {
        for j in 0..w {
            acc[i + 1][j + 1] = acc[i + 1][j] + acc[i][j + 1] - acc[i][j]
                + if s[i][j] == '.' {
                    1
                } else {
                    0
                };
        }
    }
    let mut fail = min(h, w) + 1;
    let mut pass = 1;
    while fail - pass > 1 {
        let mid = (fail + pass) / 2;
        let mut imos = vec![vec![0; w + 1]; h + 1];
        for i in 0..h + 1 - mid {
            for j in 0..w + 1 - mid {
                if acc[i + mid][j + mid] + acc[i][j] == acc[i + mid][j] + acc[i][j + mid] {
                    imos[i][j] += 1;
                    imos[i][j + mid] -= 1;
                    imos[i + mid][j] -= 1;
                    imos[i + mid][j + mid] += 1;
                }
            }
        }
        for i in 0..h + 1 {
            for j in 0..w {
                imos[i][j + 1] += imos[i][j];
            }
        }
        for i in 0..h {
            for j in 0..w + 1 {
                imos[i + 1][j] += imos[i][j];
            }
        }
        let mut ok = true;
        for i in 0..h {
            for j in 0..w {
                ok &= (imos[i][j] != 0) == (s[i][j] == '#');
            }
        }
        if ok {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    println!("{}", pass);
}
0