結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,676 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 11 ms
6,676 KB
testcase_09 WA -
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 848 ms
10,752 KB
testcase_14 AC 274 ms
10,496 KB
testcase_15 WA -
testcase_16 AC 789 ms
9,856 KB
testcase_17 AC 421 ms
9,600 KB
testcase_18 WA -
testcase_19 AC 361 ms
10,624 KB
testcase_20 AC 40 ms
6,676 KB
testcase_21 AC 174 ms
9,728 KB
testcase_22 AC 512 ms
10,368 KB
testcase_23 AC 246 ms
10,368 KB
testcase_24 AC 251 ms
10,368 KB
testcase_25 AC 469 ms
10,368 KB
testcase_26 WA -
testcase_27 AC 467 ms
10,368 KB
testcase_28 AC 330 ms
10,240 KB
testcase_29 AC 513 ms
10,880 KB
testcase_30 AC 486 ms
10,624 KB
testcase_31 AC 1,850 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];
        mp[{x[i], y[i]}] = i + 1;
    }
    UnionFind uf(n);
    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(i, id - 1);
                }
            }
        }
    }
    set<int> s;
    for (int i = 0; i < n; 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 = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (mp[{i, j}] > 0) {
                continue;
            }
            int now = sz;
            set<int> tmp;
            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) {
                        tmp.insert(uf.leader(id - 1));
                    }
                }
            }
            bool ok = false;
            for (int star : tmp) {
                if (s.count(star)) {
                    ok = true;
                }
            }
            if (tmp.size() > 0) {
                now = (ok ? now - (int)tmp.size() + 1 : now + 1);
            }
            mx = max(mx, now);
            mn = min(mn, now);
        }
    }
    cout << mn << " " << mx << endl;
}
0