提出 #52895274


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/dsu>
using namespace atcoder;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i ++) cin >> s[i];
    dsu uf(h * w);
    int dy[4] = {-1, 0, 0, 1}, dx[4] = {0, -1, 1, 0};
    auto adj_mag = [&](int i, int j) -> bool {
        for(int k = 0; k < 4; k ++) {
            int y = i + dy[k], x = j + dx[k];
            if(y < 0 or y >= h or x < 0 or x >= w) continue;
            if(s[y][x] == '#') return true;
        }
        return false;
    };
    for(int i = 0; i < h; i ++) for(int j = 0; j < w; j ++) if(!adj_mag(i, j)) {
        if(i != h - 1 and !adj_mag(i + 1, j)) {
            uf.merge(i * w + j, (i + 1) * w + j);
        }
        if(j != w - 1 and !adj_mag(i, j + 1)) {
            uf.merge(i * w + j, i * w + j + 1);
        }
    }
    vector<int> cnt(h * w);
    for(int i = 0; i < h * w; i ++) cnt[i] = uf.size(i);
    for(int i = 0; i < h; i ++) for(int j = 0; j < w; j ++) {
        if(s[i][j] != '#' and adj_mag(i, j)) {
            set<int> st;
            for(int k = 0; k < 4; k ++) {
                int y = i + dy[k], x = j + dx[k];
                if(y < 0 or y >= h or x < 0 or x >= w) continue;
                if(s[y][x] == '#') continue;
                if(!adj_mag(y, x)) st.insert(uf.leader(y * w + x));
            }
            for(int e : st) cnt[e] ++;
        }
    }
    cout << *max_element(cnt.begin(), cnt.end()) << endl;
    return 0;
}

提出情報

提出日時
問題 D - Grid and Magnet
ユーザ shinchan
言語 C++ 20 (gcc 12.2)
得点 425
コード長 1539 Byte
結果 AC
実行時間 73 ms
メモリ 13064 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 2
AC × 52
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.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, 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
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3520 KiB
example_01.txt AC 1 ms 3416 KiB
hand_00.txt AC 1 ms 3392 KiB
hand_01.txt AC 45 ms 12968 KiB
hand_02.txt AC 19 ms 12972 KiB
hand_03.txt AC 26 ms 12880 KiB
hand_04.txt AC 59 ms 12916 KiB
hand_05.txt AC 46 ms 12896 KiB
hand_06.txt AC 46 ms 12920 KiB
hand_07.txt AC 47 ms 12968 KiB
hand_08.txt AC 45 ms 12944 KiB
hand_09.txt AC 45 ms 13060 KiB
hand_10.txt AC 46 ms 12892 KiB
hand_11.txt AC 1 ms 3508 KiB
hand_12.txt AC 1 ms 3576 KiB
hand_13.txt AC 1 ms 3604 KiB
random_00.txt AC 49 ms 12704 KiB
random_01.txt AC 48 ms 12976 KiB
random_02.txt AC 47 ms 12636 KiB
random_03.txt AC 65 ms 12880 KiB
random_04.txt AC 66 ms 12896 KiB
random_05.txt AC 65 ms 12896 KiB
random_06.txt AC 73 ms 12932 KiB
random_07.txt AC 73 ms 12820 KiB
random_08.txt AC 73 ms 12896 KiB
random_09.txt AC 56 ms 12932 KiB
random_10.txt AC 55 ms 12888 KiB
random_11.txt AC 55 ms 12632 KiB
random_12.txt AC 20 ms 12892 KiB
random_13.txt AC 20 ms 12896 KiB
random_14.txt AC 20 ms 12964 KiB
random_15.txt AC 45 ms 12896 KiB
random_16.txt AC 44 ms 12900 KiB
random_17.txt AC 48 ms 12912 KiB
random_18.txt AC 19 ms 12636 KiB
random_19.txt AC 19 ms 12880 KiB
random_20.txt AC 20 ms 12920 KiB
random_21.txt AC 26 ms 12796 KiB
random_22.txt AC 26 ms 12792 KiB
random_23.txt AC 28 ms 12884 KiB
random_24.txt AC 53 ms 12800 KiB
random_25.txt AC 54 ms 12880 KiB
random_26.txt AC 54 ms 12900 KiB
random_27.txt AC 54 ms 13064 KiB
random_28.txt AC 54 ms 12896 KiB
random_29.txt AC 54 ms 12632 KiB
random_30.txt AC 58 ms 12900 KiB
random_31.txt AC 59 ms 12892 KiB
random_32.txt AC 59 ms 12628 KiB
random_33.txt AC 59 ms 12884 KiB
random_34.txt AC 59 ms 12884 KiB
random_35.txt AC 59 ms 12896 KiB