結果

問題 No.2456 Stamp Art
ユーザー milanis48663220milanis48663220
提出日時 2023-09-01 22:45:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,766 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 124,836 KB
実行使用メモリ 86,136 KB
最終ジャッジ日時 2023-09-01 22:45:29
合計ジャッジ時間 7,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 100 ms
85,808 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 256 ms
85,872 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 315 ms
85,920 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 304 ms
85,840 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


template<typename T>
class CumsumGrid{
    public:
    CumsumGrid(vector<vector<T>> v): v(v){
        n = v.size();
        m = v[0].size();
        v_cumsum = vector<vector<T>>(n+1, vector<T>(m+1, T(0)));
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++){
                v_cumsum[i+1][j+1] = v_cumsum[i+1][j]+v_cumsum[i][j+1]-v_cumsum[i][j]+v[i][j];
            }
        }
    }
    /**
     * sum(v[il:ir)[jl:jr))
     */ 
    T sum(int il, int ir, int jl, int jr){
        if(ir <= il) return T(0);
        if(jr <= jl) return T(0);
        if(ir > n) ir = n;
        if(jr > m) jr = m;
        if(il < 0) il = 0;
        if(jl < 0) jl = 0;
        return v_cumsum[ir][jr]-v_cumsum[ir][jl]-v_cumsum[il][jr]+v_cumsum[il][jl];
    }
    private:
    int n, m;
    vector<vector<T>> v;
    vector<vector<T>> v_cumsum;
};

int imos[2005][2005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];
    auto c = vec2d(h, w, 0);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.') c[i][j] = 1;
        }
    }
    auto cumsum = CumsumGrid<int>(c);
    auto clear = [&](){
        for(int i = 0; i <= h; i++){
            for(int j = 0; j <= w; j++){
                imos[i][j] = 0;
            }
        }
    };
    auto ok = [&](int len){
        for(int i = 0; i+len <= h; i++){
            for(int j = 0; j+len <= w; j++){
                if(cumsum.sum(i, i+len, j, j+len) == 0){
                    imos[i][j]++;
                    imos[i+len][j]--;
                    imos[i][j+len]--;
                    imos[i+len][j+len]++;
                }
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 1; j <= w; j++){
                imos[i][j] += imos[i][j-1];
            }
        }
        for(int i = 1; i <= h; i++){
            for(int j = 0; j < w; j++){
                imos[i][j] += imos[i-1][j];
            }
        }
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++){
                bool black = s[i][j] == '#';
                bool cur_black = imos[i][j] > 0;
                if(black != cur_black) return false;
            }
        }
        return true;
    };

    int l = 1, r = min(h, w);
    if(ok(r)){
        cout << r << endl;
        return 0;
    }
    while(r-l > 1){
        int len = (l+r)/2;
        if(ok(len)) l = len;
        else r = len;
    }
    cout << l << endl;
}
0