結果

問題 No.2696 Sign Creation
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-03-23 00:12:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,208 bytes
コンパイル時間 2,776 ms
コンパイル使用メモリ 222,256 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-03-23 00:12:48
合計ジャッジ時間 12,169 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 AC 11 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 8 ms
6,676 KB
testcase_11 AC 18 ms
6,676 KB
testcase_12 AC 18 ms
6,676 KB
testcase_13 AC 706 ms
11,008 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 640 ms
9,984 KB
testcase_17 AC 435 ms
10,112 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 40 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 484 ms
10,880 KB
testcase_28 AC 331 ms
10,752 KB
testcase_29 AC 517 ms
11,392 KB
testcase_30 WA -
testcase_31 AC 1,443 ms
11,520 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 5 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct UnionFind {
    int n;
    vector<int> par, siz;
    UnionFind(int n_) : n(n_), par(n_, -1), siz(n_, 1) {}
    int leader(int x) {
        if (par[x] == -1) {
            return x;
        } else {
            return par[x] = leader(par[x]);
        }
    }
    bool same(int x, int y) {
        return leader(x) == leader(y);
    }
    bool merge(int x, int y) {
        x = leader(x);
        y = leader(y);
        if (x == y) {
            return false;
        }
        if (siz[x] < siz[y]) {
            swap(x, y);
        }
        par[y] = x;
        siz[x] += siz[y];
        return true;
    }
    int size(int x) {
        return siz[leader(x)];
    }
    vector<vector<int>> groups() {
        vector<vector<int>> member(n);
        for (int i = 0; i < n; i++) {
            member[leader(i)].push_back(i);
        }
        vector<vector<int>> result;
        for (int i = 0; i < n; i++) {
              if (member[i].size() > 0) {
                  result.push_back(member[i]);
              }
        }
        return result;
    }
};

int main() {
    int h, w, n, d;
    cin >> h >> w >> n >> d;
    vector<int> x(n), y(n);
    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        mp[{x[i], y[i]}] = i + 1;
    }
    UnionFind uf(h * w);
    for (int i = 0; i < n; i++) {
        int a = x[i], b = y[i];
        for (int j = -d; j <= d; j++) {
            for (int k = -d; k <= d; k++) {
                if (abs(j) + abs(k) > d) {
                    continue;
                }
                int na = a + j, nb = b + k;
                int id = mp[{na, nb}];
                if (id > 0) {
                    uf.merge(w * a + b, w * na + nb);
                }
            }
        }
    }
    set<int> s;
    for (int i = 0; i < h * w; i++) {
        int ld = uf.leader(i);
        if (uf.size(ld) >= 2) {
            s.insert(ld);
        }
    }
    int sz = s.size();
    //周りにある星座の種類数
    int mx = 0, mn = 2000000000;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (mp[{i, j}] > 0) {
                continue;
            }
            int now = sz;
            bool seiza = false, one = false;
            for (int k = -d; k <= d; k++) {
                for (int l = -d; l <= d; l++) {
                    if (abs(k) + abs(l) > d) {
                        continue;
                    }
                    int ni = i + k, nj = j + l;
                    int id = mp[{ni, nj}];
                    if (id > 0) {
                        int si = x[id - 1], sj = y[id - 1];
                        if (uf.size(uf.leader(w * si + sj)) >= 2) {
                            seiza = true;
                        } else {
                            one = true;
                        }
                    }
                }
            }
            if (seiza) {
                now = max(1, now - 1);
            } else if (one) {
                now++;
            }
            mx = max(mx, now);
            mn = min(mn, now);
        }
    }
    cout << mn << " " << mx << endl;
}
0