QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176103 | #6880. Operation Hope | Nyans | WA | 1667ms | 28872kb | C++14 | 1.9kb | 2023-09-11 10:51:28 | 2023-09-11 10:51:28 |
Judging History
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];
void dfs(int u) {
vis[u] = 1;
for (int i = 0; i < 3; ++i) if (fr[i] < tl[i]) {
for (int &j = fr[i]; j < Lp[i][u]; ++j)
if (!vis[id[i][j] ^ 1]) dfs(id[i][j] ^ 1);
for (int &j = tl[i]; j > Rp[i][u]; --j)
if (!vis[id[i][j] ^ 1]) dfs(id[i][j] ^ 1);
}
stk[++tp] = u;
}
void sfd(int u) {
col[u] = F;
if (col[u ^ 1] == F || F == -1) return F = -1, void();
for (int i = 0; i < 3; ++i) if (fr[i] < tl[i]) {
for (int &j = fr[i]; j < Lp[i][u ^ 1]; ++j)
if (!col[id[i][j]]) sfd(id[i][j]);
for (int &j = tl[i]; j > Rp[i][u ^ 1]; --j)
if (!col[id[i][j]]) sfd(id[i][j]);
}
}
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] = col[i] = 0;
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 (!col[stk[i]]) ++F, sfd(stk[i]);
if (~F) R = mid - 1;
else L = mid + 1;
}
printf("%d\n", L);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1667ms
memory: 28872kb
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:
983040437 908462863 99919477 99774690 99922111 99914205 99946480 99849310 114372 976971790 910558223 99965775 99807900 99959755 99858165 99900104 99981039 114408 988416638 908987185 99948914 99680790 99821819 99927070 99827404 99854234 114334 985343382 919276335 99973920 99836490 99818752 99826757 9...
result:
wrong answer 1st lines differ - expected: '982758431', found: '983040437'