# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481428 | 2021-10-20T19:12:17 Z | rainboy | Matching (COCI20_matching) | C | 0 ms | 280 KB |
#include <stdio.h> #include <string.h> #define N 100000 int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int *zz; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) if (zz[ii[j]] == zz[i_]) j++; else if (zz[ii[j]] < zz[i_]) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } sort(ii, l, i); l = k; } } int xx[N], yy[N]; int intersect_(int x1, int x2, int x3, int x4) { int tmp; if (x1 > x2) tmp = x1, x1 = x2, x2 = tmp; if (x3 > x4) tmp = x3, x3 = x4, x4 = tmp; return max(x1, x3) <= min(x2, x4); } int intersect(int i1, int j1, int i2, int j2) { return intersect_(xx[i1], xx[j1], xx[i2], xx[j2]) && intersect_(yy[i1], yy[j1], yy[i2], yy[j2]); } int ds[(N + 1) * 2]; int find(int i) { return ds[i] < 0 ? i : (ds[i] = find(ds[i])); } void join(int i, int j) { i = find(i); j = find(j); if (i == j) return; if (ds[i] > ds[j]) ds[i] = j; else { if (ds[i] == ds[j]) ds[i]--; ds[j] = i; } } int main() { static int ii[N], uu[N], vv[N], dd[N], cc[N + 1]; int n, m, h, h_, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &xx[i], &yy[i]); for (i = 0; i < n; i++) ii[i] = i; m = 0; zz = xx, sort(ii, 0, n); for (i = 0; i < n; i++) if (i + 1 < n && xx[ii[i]] == xx[ii[i + 1]]) { uu[m] = ii[i], vv[m] = ii[i + 1], m++; dd[ii[i]]++, dd[ii[i + 1]]++; } zz = yy, sort(ii, 0, n); for (i = 0; i < n; i++) if (i + 1 < n && yy[ii[i]] == yy[ii[i + 1]]) { uu[m] = ii[i], vv[m] = ii[i + 1], m++; dd[ii[i]]++, dd[ii[i + 1]]++; } for (i = 0; i < n; i++) if (dd[i] == 0) { printf("NE\n"); return 0; } memset(ds, -1, (m + 1) * 2 * sizeof *ds); for (h = 0; h < m; h++) for (h_ = h + 1; h_ < m; h_++) if (intersect(uu[h], vv[h], uu[h_], vv[h_])) join(h << 1 | 0, h_ << 1 | 1), join(h << 1 | 1, h_ << 1 | 0); for (h = 0; h < m; h++) if (dd[uu[h]] == 1 || dd[vv[h]] == 1) join(h << 1 | 0, m << 1 | 1), join(h << 1 | 1, m << 1 | 0); for (h = 0; h < m; h++) if (find(h << 1 | 0) == find(h << 1 | 1)) { printf("NE\n"); return 0; } for (h = 0; h <= m; h++) cc[h] = find(h << 1 | 0) < find(h << 1 | 1); if (cc[m]) for (h = 0; h <= m; h++) if (find(h << 1 | 0) == find(m << 1 | 0) || find(h << 1 | 0) == find(m << 1 | 0)) cc[h] ^= 1; printf("DA\n"); for (h = 0; h < m; h++) if (cc[h]) printf("%d %d\n", uu[h] + 1, vv[h] + 1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 280 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 280 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 280 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Incorrect | 0 ms | 204 KB | Unexpected end of file - int32 expected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 280 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 280 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Incorrect | 0 ms | 204 KB | Unexpected end of file - int32 expected |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 280 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 280 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Incorrect | 0 ms | 204 KB | Unexpected end of file - int32 expected |
10 | Halted | 0 ms | 0 KB | - |