QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#176199#6880. Operation HopeNyansWA 1176ms29272kbC++142.1kb2023-09-11 11:56:412023-09-11 11:56:41

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 11:56:41]
  • 评测
  • 测评结果:WA
  • 用时:1176ms
  • 内存:29272kb
  • [2023-09-11 11:56:41]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <algorithm>
int T, n, a[3][200010], id[3][200010], Lp[3][200010], Rp[3][200010];
int vis[200010], stk[200010], tp, col[200010], F;
int fr[3], tl[3];
int q[200010];
void dfs(int u) {
	vis[u] = 0;
	for (int i = 0; i < 3; ++i) {
		while (fr[i] < Lp[i][u]) {
			int u = id[i][fr[i]++] ^ 1;
			if (vis[u]) dfs(u);
		}
		while (tl[i] > Rp[i][u]) {
			int u = id[i][tl[i]--] ^ 1;
			if (vis[u]) dfs(u);
		}
		if (fr[i] > tl[i]) break;
	}
	stk[++tp] = u;
}
int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n); n *= 2;
		for (int i = 0; i < n; ++i) for (int k = 0; k < 3; ++k) scanf("%d", &a[k][i]);
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < n; ++j) id[i][j] = j;
			std::sort(id[i], id[i] + n, [i](int x, int y) { return a[i][x] < a[i][y]; });
		}
		int L = 0, R = 1e9;
		while (L <= R) {
			int mid = (L + R) / 2;
			for (int i = 0; i < 3; ++i) {
				for (int k = 0, r = 0; k < n; ++k) {
					int j = id[i][k];
					while (a[i][id[i][r]] + mid < a[i][j]) ++r;
					Lp[i][j] = r;
				}
				for (int k = n - 1, l = n - 1; k >= 0; --k) {
					int j = id[i][k];
					while (a[i][j] + mid < a[i][id[i][l]]) --l;
					Rp[i][j] = l;
				}
			}
			for (int i = 0; i < 3; ++i) fr[i] = 0, tl[i] = n - 1;
			for (int i = 0; i < n; ++i) vis[i] = 1;
			for (int i = 0; i < n; ++i) if (vis[i]) dfs(i);
			for (int i = 0; i < 3; ++i) fr[i] = 0, tl[i] = n - 1; F = tp = 0;
			for (int i = n; i && ~F; --i) if (!vis[stk[i]]) {
				q[1] = stk[i], col[stk[i]] = ++F;
				int f = 0, t = 1;
				while (f < t) {
					if (fr[0] > tl[0] || fr[1] > tl[1] || fr[2] > tl[2]) break;
					int u = q[++f];
					if (col[u ^ 1] == F) {
						F = -1;
						break;
					}
					for (int i = 0; i < 3; ++i) {
						while (fr[i] < Lp[i][u ^ 1]) {
							int u = id[i][fr[i]++];
							if (!col[u]) col[u] = F, q[++t] = u;
						}
						while (tl[i] > Rp[i][u ^ 1]) {
							int u = id[i][tl[i]--];
							if (!col[u]) col[u] = F, q[++t] = u;
						}
					}
				}
			}
			if (~F) R = mid - 1;
			else L = mid + 1;
		}
		printf("%d\n", L);
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1176ms
memory: 29272kb

input:

99
1000
532114032 55099632 197592060 601440117 964448551 693620489
68503446 149314803 308777541 408078601 977772348 978400861
185066959 236214410 460480442 842502015 709303988 675932475
793016330 161748857 511444978 852914351 281720292 552030608
9982160 15933748 8254470 175080600 567563770 461489051...

output:

1000000001
1000000001
124999999
0
89843749
1000000001
1000000001
1000000001
1000000001
543945312
500000000
562500000
0
0
1000000001
1000000001
1000000001
1000000001
0
0
250000000
0
1000000001
1000000001
1000000001
1000000001
1000000001
0
585937500
1000000001
97656249
0
0
0
0
93749999
0
875000000
100...

result:

wrong answer 1st lines differ - expected: '982758431', found: '1000000001'