結果

問題 No.2897 2集合間距離
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-09-20 21:55:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 3,500 ms
コード長 882 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 208,872 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-09-20 21:55:51
合計ジャッジ時間 5,150 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
19,200 KB
testcase_01 AC 16 ms
19,200 KB
testcase_02 AC 16 ms
19,328 KB
testcase_03 AC 15 ms
19,200 KB
testcase_04 AC 16 ms
19,200 KB
testcase_05 AC 17 ms
19,200 KB
testcase_06 AC 17 ms
19,200 KB
testcase_07 AC 18 ms
19,200 KB
testcase_08 AC 17 ms
19,200 KB
testcase_09 AC 17 ms
19,200 KB
testcase_10 AC 16 ms
19,072 KB
testcase_11 AC 16 ms
19,200 KB
testcase_12 AC 18 ms
19,200 KB
testcase_13 AC 17 ms
19,456 KB
testcase_14 AC 21 ms
19,456 KB
testcase_15 AC 27 ms
19,328 KB
testcase_16 AC 239 ms
20,992 KB
testcase_17 AC 255 ms
20,736 KB
testcase_18 AC 227 ms
20,864 KB
testcase_19 AC 225 ms
20,736 KB
testcase_20 AC 231 ms
20,736 KB
testcase_21 AC 220 ms
20,736 KB
testcase_22 AC 223 ms
20,864 KB
testcase_23 AC 224 ms
20,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	int H = 2020, W = 2020;
	vector A(H, vector(W, 0));
	while (N--) {
		int x, y;
		cin >> x >> y;
		x ++; y ++;
		A[x + y][x - y + 1000] ++;
	}
	for (int i = 1; i < H; i ++) {
		for (int j = 1; j < W; j ++) {
			A[i][j] += A[i][j - 1] + A[i - 1][j] - A[i - 1][j - 1];
		}
	}
	cin >> N;
	vector<pair<int, int>> B(N);
	for (auto& [x, y] : B) {
		int a, b;
		cin >> a >> b;
		a ++; b ++;
		x = a + b;
		y = a - b + 1000;
	}
	int ok = H, ng = -1;
	while (abs(ok - ng) > 1) {
		int mu = (ok + ng) / 2;
		bool ex = false;
		for (auto& [x, y] : B) {
			int a1 = min(H-1, x + mu), b1 = min(W-1, y + mu),
			a2 = max(0, x - mu - 1), b2 = max(0, y - mu - 1);
			int c = A[a1][b1] + A[a2][b2] - A[a1][b2] - A[a2][b1];
			ex = ex || c;
		}
		if (ex) {
			ok = mu;
		} else {
			ng = mu;
		}
	}
	cout << ok << endl;
}
0