Submission #73585080


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
template<class T> bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
const ll inf = 1e18;
const ll MOD = 1e9 + 7;

const ll dx[] = {0,-1,-1,0};
const ll dy[] = {0,-1,0,-1};

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll t;
    cin >> t;
    rep(qt,t) {
        ll h,w;
        cin >>h >> w;
        vector<string> S(h);
        vector<vector<ll>> A(h,vector<ll>(w));
        vector<vector<ll>> B(h,vector<ll>(w));
        rep(i,h) cin >> S[i];
        for(ll i = 0;i<h-1;i++) {
            for(ll j = 0;j<w-1;j++) {
                if(S[i][j]=='#'&&S[i+1][j]=='#'&&S[i][j+1]=='#'&&S[i+1][j+1]=='#') {
                    A[i][j]++;
                    A[i+1][j]++;
                    A[i][j+1]++;
                    A[i+1][j+1]++;
                    B[i][j]++;
                }
            }
        }

        
        ll cnt = 0;
        for(ll c = 4;c>=1;c--) {
            for(ll i = 0;i<h-1;i++) {
                for(ll j = 0;j<w-1;j++) {
                    if(A[i][j] == c) {
                        cnt++;
                        rep(v,4) {
                            ll ni = i + dx[v];
                            ll nj = j + dy[v];
                            if(0<=ni&&ni<=h-1&&0<=nj&&nj<=w-1) {
                                if(B[ni][nj]==1) {
                                    A[ni][nj]--;
                                    A[ni+1][nj]--;
                                    A[ni][nj+1]--;
                                    A[ni+1][nj+1]--;
                                    B[ni][nj] = 0;
                            }
                            
                            }
                            
                        }
                      
                    }
                }
            }
        }

        cout << cnt << "\n";
    }
    
    return 0;
}

Submission Info

Submission Time
Task G - 2x2 Erasing 2
User hikoten
Language C++23 (GCC 15.2.0)
Score 0
Code Size 2178 Byte
Status WA
Exec Time 1 ms
Memory 3672 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 1
AC × 8
WA × 19
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.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, 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
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3604 KiB
hand_00.txt AC 1 ms 3656 KiB
hand_01.txt AC 1 ms 3656 KiB
hand_02.txt AC 1 ms 3636 KiB
hand_03.txt WA 1 ms 3540 KiB
hand_04.txt WA 1 ms 3560 KiB
hand_05.txt AC 1 ms 3672 KiB
random_00.txt WA 1 ms 3556 KiB
random_01.txt AC 1 ms 3604 KiB
random_02.txt AC 1 ms 3552 KiB
random_03.txt AC 1 ms 3672 KiB
random_04.txt WA 1 ms 3576 KiB
random_05.txt WA 1 ms 3636 KiB
random_06.txt WA 1 ms 3604 KiB
random_07.txt WA 1 ms 3560 KiB
random_08.txt WA 1 ms 3540 KiB
random_09.txt WA 1 ms 3580 KiB
random_10.txt WA 1 ms 3560 KiB
random_11.txt WA 1 ms 3576 KiB
random_12.txt WA 1 ms 3604 KiB
random_13.txt WA 1 ms 3656 KiB
random_14.txt WA 1 ms 3488 KiB
random_15.txt WA 1 ms 3596 KiB
random_16.txt WA 1 ms 3520 KiB
random_17.txt WA 1 ms 3580 KiB
random_18.txt WA 1 ms 3596 KiB
random_19.txt WA 1 ms 3488 KiB