Submission #21472353


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct Ruisekiwa2D {
    int VH, VW;
    using T = int;
    vector<vector<T>> v;
    bool needBuild = false;
    Ruisekiwa2D() { }
    Ruisekiwa2D(int w, int h) { init(w, h); }
    void init(int w, int h) {
        needBuild = true;
        VH = h; VW = w;
        v.clear();
        v.resize(h, vector<T>(w));
        rep(y, 0, VH) rep(x, 0, VW) v[y][x] = 0;
    }
    void set(int x, int y, T c) { v[y][x] = c; }
    void add(int x, int y, T c) { v[y][x] += c; }
    void build() {
        rep(y, 0, VH) rep(x, 0, VW) {
            if (0 < y) v[y][x] += v[y - 1][x];
            if (0 < x) v[y][x] += v[y][x - 1];
            if (0 < y && 0 < x) v[y][x] -= v[y - 1][x - 1];
        }
        needBuild = false;
    }
    // [sx,sy]-[tx,ty]
    T get(int sx, int tx, int sy, int ty) {
        if (needBuild) assert(0 && "Need Build");
        if (tx < sx or ty < sy) return 0;
        T rs = v[ty][tx];
        if (0 < sx) rs -= v[ty][sx - 1];
        if (0 < sy) rs -= v[sy - 1][tx];
        if (0 < sx && 0 < sy) rs += v[sy - 1][sx - 1];
        return rs;
    }


    // getTo...
    enum { UP = 0, RIGHT, DOWN, LEFT };
    T getTo(int x, int y, int len, int to) {
        switch (to)
        {
        case UP: return getToUp(x, y, len);
        case RIGHT: return getToRight(x, y, len);
        case DOWN: return getToDown(x, y, len);
        case LEFT: return getToLeft(x, y, len);
        }
        assert(0);
    }
    T getToDown(int x, int y, int len) {
        if (needBuild) assert(0 && "Need Build");
        if (VH - y < len) len = VH - y;
        return get(x, x, y, y + len - 1);
    }
    T getToUp(int x, int y, int len) {
        if (needBuild) assert(0 && "Need Build");
        if (y + 1 < len) len = y + 1;
        return get(x, x, y - len + 1, y);
    }
    T getToRight(int x, int y, int len) {
        if (needBuild) assert(0 && "Need Build");
        if (VW - x < len) len = VW - x;
        return get(x, x + len - 1, y, y);
    }
    T getToLeft(int x, int y, int len) {
        if (needBuild) assert(0 && "Need Build");
        if (x + 1 < len) len = x + 1;
        return get(x - len + 1, x, y, y);
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int H, W, K;
string S[30];
Ruisekiwa2D r2d[10];
//---------------------------------------------------------------------------------------------------
bool check(int len) {
    rep(y, 0, H - len + 1) rep(x, 0, W - len + 1) rep(d, 0, 10) {
        int ng = len * len - r2d[d].get(x, x + len - 1, y, y + len - 1);
        if (ng <= K) return true;
    }
    return false;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> K;
    rep(y, 0, H) cin >> S[y];
    rep(i, 0, 10) r2d[i].init(W, H);
    rep(y, 0, H) rep(x, 0, W) r2d[S[y][x] - '0'].add(x, y, 1);
    rep(i, 0, 10) r2d[i].build();

    rrep(n, min(H, W), 1) if (check(n)) {
        cout << n << endl;
        return;
    }
}





Submission Info

Submission Time
Task H - マス目のカット
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 4289 Byte
Status AC
Exec Time 7 ms
Memory 3684 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 2
AC × 62
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random2_10.txt, random2_11.txt, random2_12.txt, random2_13.txt, random2_14.txt, random2_15.txt, random2_16.txt, random2_17.txt, random2_18.txt, random2_19.txt, random2_20.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, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random2_01.txt AC 7 ms 3604 KB
random2_02.txt AC 4 ms 3580 KB
random2_03.txt AC 4 ms 3668 KB
random2_04.txt AC 2 ms 3680 KB
random2_05.txt AC 3 ms 3532 KB
random2_06.txt AC 2 ms 3596 KB
random2_07.txt AC 2 ms 3640 KB
random2_08.txt AC 2 ms 3684 KB
random2_09.txt AC 2 ms 3648 KB
random2_10.txt AC 2 ms 3488 KB
random2_11.txt AC 3 ms 3496 KB
random2_12.txt AC 1 ms 3480 KB
random2_13.txt AC 2 ms 3560 KB
random2_14.txt AC 2 ms 3560 KB
random2_15.txt AC 2 ms 3612 KB
random2_16.txt AC 1 ms 3660 KB
random2_17.txt AC 3 ms 3484 KB
random2_18.txt AC 2 ms 3576 KB
random2_19.txt AC 2 ms 3568 KB
random2_20.txt AC 2 ms 3560 KB
random_01.txt AC 3 ms 3604 KB
random_02.txt AC 2 ms 3488 KB
random_03.txt AC 2 ms 3548 KB
random_04.txt AC 6 ms 3644 KB
random_05.txt AC 2 ms 3600 KB
random_06.txt AC 2 ms 3600 KB
random_07.txt AC 2 ms 3596 KB
random_08.txt AC 2 ms 3636 KB
random_09.txt AC 2 ms 3684 KB
random_10.txt AC 2 ms 3648 KB
random_11.txt AC 2 ms 3500 KB
random_12.txt AC 3 ms 3572 KB
random_13.txt AC 2 ms 3484 KB
random_14.txt AC 2 ms 3492 KB
random_15.txt AC 2 ms 3632 KB
random_16.txt AC 2 ms 3628 KB
random_17.txt AC 3 ms 3512 KB
random_18.txt AC 2 ms 3492 KB
random_19.txt AC 2 ms 3496 KB
random_20.txt AC 2 ms 3452 KB
random_21.txt AC 3 ms 3540 KB
random_22.txt AC 2 ms 3664 KB
random_23.txt AC 2 ms 3508 KB
random_24.txt AC 3 ms 3496 KB
random_25.txt AC 2 ms 3600 KB
random_26.txt AC 2 ms 3640 KB
random_27.txt AC 2 ms 3640 KB
random_28.txt AC 2 ms 3668 KB
random_29.txt AC 2 ms 3608 KB
random_30.txt AC 3 ms 3504 KB
random_31.txt AC 2 ms 3620 KB
random_32.txt AC 2 ms 3448 KB
random_33.txt AC 2 ms 3552 KB
random_34.txt AC 2 ms 3544 KB
random_35.txt AC 2 ms 3572 KB
random_36.txt AC 2 ms 3636 KB
random_37.txt AC 2 ms 3480 KB
random_38.txt AC 2 ms 3584 KB
random_39.txt AC 2 ms 3608 KB
random_40.txt AC 2 ms 3480 KB
sample_01.txt AC 1 ms 3548 KB
sample_02.txt AC 3 ms 3600 KB