結果

問題 No.2696 Sign Creation
ユーザー haihamabossuhaihamabossu
提出日時 2024-04-16 23:45:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,500 ms
コード長 1,903 bytes
コンパイル時間 2,872 ms
コンパイル使用メモリ 215,564 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-16 23:45:33
合計ジャッジ時間 5,835 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 73 ms
5,376 KB
testcase_14 AC 45 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 AC 63 ms
5,376 KB
testcase_17 AC 17 ms
5,376 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 31 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 22 ms
5,888 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 25 ms
5,376 KB
testcase_24 AC 26 ms
5,376 KB
testcase_25 AC 38 ms
5,376 KB
testcase_26 AC 18 ms
5,376 KB
testcase_27 AC 23 ms
5,376 KB
testcase_28 AC 20 ms
5,376 KB
testcase_29 AC 18 ms
5,376 KB
testcase_30 AC 17 ms
5,376 KB
testcase_31 AC 71 ms
7,808 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/dsu>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve() {
  ll h, w, n, d;
  cin >> h >> w >> n >> d;
  vector grid(h, vector<ll>(w, -1));
  rep(ni, n) {
    ll x, y;
    cin >> x >> y, x--, y--;
    grid[x][y] = ni;
  }
  atcoder::dsu dsu(n);
  rep(x, h) rep(y, w) {
    ll ni = grid[x][y];
    if (ni == -1)
      continue;
    for (ll xi = x - d; xi <= x + d; xi++) {
      if (xi < 0 || h <= xi)
        continue;
      ll dx = abs(x - xi);
      for (ll yi = y - d + dx; yi <= y + d - dx; yi++) {
        if (yi < 0 || w <= yi)
          continue;
        ll nj = grid[xi][yi];
        if (nj == -1 || ni == nj)
          continue;
        dsu.merge(ni, nj);
      }
    }
  }
  ll orig = 0;
  for (const auto &g : dsu.groups()) {
    if (g.size() >= 2)
      orig++;
  }
  ll ans_min = orig, ans_max = orig;
  rep(x, h) rep(y, w) {
    if (grid[x][y] != -1)
      continue;
    set<ll> st;
    vector<ll> cnt(3);
    for (ll xi = x - d; xi <= x + d; xi++) {
      if (xi < 0 || h <= xi)
        continue;
      ll dx = abs(x - xi);
      for (ll yi = y - d + dx; yi <= y + d - dx; yi++) {
        if (yi < 0 || w <= yi)
          continue;
        ll nj = grid[xi][yi];
        if (nj == -1)
          continue;
        nj = dsu.leader(nj);
        if (st.count(nj) == 1)
          continue;
        st.insert(nj);
        cnt[min(dsu.size(nj), 2)] += 1;
      }
    }
    if (st.empty())
      continue;
    ll now = orig;
    if (cnt[1]) {
      now += 1;
      now -= cnt[2];
    } else {
      now -= cnt[2] - 1;
    }
    ans_min = min(ans_min, now);
    ans_max = max(ans_max, now);
  }
  cout << ans_min << ' ' << ans_max << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0