Submission #994851
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N = 333; vector <int> g[N * N]; bool alive_a[N * N], alive_b[N * N]; int pa[N * N], pb[N * N], was[N * N]; int it; bool dfs(int v) { was[v] = it; for (int j = 0; j < (int) g[v].size(); j++) { int u = g[v][j]; if (alive_b[u] && pb[u] == -1) { pa[v] = u; pb[u] = v; return true; } } for (int j = 0; j < (int) g[v].size(); j++) { int u = g[v][j]; if (alive_b[u] && was[pb[u]] != it) { if (dfs(pb[u])) { pa[v] = u; pb[u] = v; return true; } } } return false; } bool dfs_finish(int v, int finish) { if (pa[v] == finish) { return true; } int old = pa[v]; pa[v] = -1; pb[old] = -1; it++; if (dfs(pb[finish])) { pa[v] = finish; pb[finish] = v; return true; } pa[v] = old; pb[old] = v; return false; } int what[N * N]; int U[N], D[N], L[N], R[N]; int empty[N][N]; int first_L[N], first_R[N], first_U[N], first_D[N]; int cell_L[N], cell_R[N], cell_U[N], cell_D[N]; int n; void take_cell(int i, int j) { alive_b[i * n + j] = false; empty[i][j] = 0; if (cell_L[i] == j) { while (cell_L[i] < n && !empty[i][cell_L[i]]) { cell_L[i]++; } } if (cell_R[i] == j) { while (cell_R[i] >= 0 && !empty[i][cell_R[i]]) { cell_R[i]--; } } if (cell_U[j] == i) { while (cell_U[j] < n && !empty[cell_U[j]][j]) { cell_U[j]++; } } if (cell_D[j] == i) { while (cell_D[j] >= 0 && !empty[cell_D[j]][j]) { cell_D[j]--; } } } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", U + i); } for (int i = 0; i < n; i++) { scanf("%d", D + i); } for (int i = 0; i < n; i++) { scanf("%d", L + i); } for (int i = 0; i < n; i++) { scanf("%d", R + i); } int cnt = 0; for (int i = 0; i < n; i++) { first_L[i] = cnt; for (int j = 0; j < L[i]; j++) { what[cnt++] = i; } first_R[i] = cnt; for (int j = 0; j < R[i]; j++) { what[cnt++] = i; } } for (int i = 0; i < n; i++) { first_U[i] = cnt; for (int j = 0; j < U[i]; j++) { what[cnt++] = ~i; } first_D[i] = cnt; for (int j = 0; j < D[i]; j++) { what[cnt++] = ~i; } } for (int k = 0; k < cnt; k++) { if (what[k] >= 0) { for (int j = 0; j < n; j++) { g[k].push_back(what[k] * n + j); } } else { for (int i = 0; i < n; i++) { g[k].push_back(i * n + (~what[k])); } } } for (int i = 0; i < cnt; i++) { pa[i] = -1; pb[i] = -1; was[i] = -1; } for (int i = 0; i < n * n; i++) { alive_a[i] = true; alive_b[i] = true; } for (int i = 0; i < cnt; i++) { it++; if (!dfs(i)) { puts("NO"); return 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { empty[i][j] = 1; } } for (int i = 0; i < n; i++) { cell_L[i] = 0; cell_R[i] = n - 1; cell_U[i] = 0; cell_D[i] = n - 1; } for (int iter = 0; iter < n * n; iter++) { bool found = false; for (int i = 0; i < n; i++) { if (L[i] > 0) { int j = cell_L[i]; if (dfs_finish(first_L[i], i * n + j)) { printf("L%d\n", i + 1); L[i]--; alive_a[first_L[i]] = false; first_L[i]++; take_cell(i, j); found = true; break; } } } if (found) { continue; } for (int i = 0; i < n; i++) { if (R[i] > 0) { int j = cell_R[i]; if (dfs_finish(first_R[i], i * n + j)) { printf("R%d\n", i + 1); R[i]--; alive_a[first_R[i]] = false; first_R[i]++; take_cell(i, j); found = true; break; } } } if (found) { continue; } for (int j = 0; j < n; j++) { if (U[j] > 0) { int i = cell_U[j]; if (dfs_finish(first_U[j], i * n + j)) { printf("U%d\n", j + 1); U[j]--; alive_a[first_U[j]] = false; first_U[j]++; take_cell(i, j); found = true; break; } } } if (found) { continue; } for (int j = 0; j < n; j++) { if (D[j] > 0) { int i = cell_D[j]; if (dfs_finish(first_D[j], i * n + j)) { printf("D%d\n", j + 1); D[j]--; alive_a[first_D[j]] = false; first_D[j]++; take_cell(i, j); found = true; break; } } } assert(found); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | J - Neue Spiel |
User | tourist |
Language | C++14 (GCC 5.4.1) |
Score | 2000 |
Code Size | 4833 Byte |
Status | TLE |
Exec Time | 4213 ms |
Memory | 190848 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:87:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:89:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", U + i); ^ ./Main.cpp:92:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", D + i); ^ ./Main.cpp:95:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", L + i); ^ ./Main.cpp:98:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", R + i); ^
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 2000 / 2000 | 0 / 100 | ||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
dataset1 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt |
dataset2 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 5 ms | 2944 KB |
01-02.txt | AC | 5 ms | 2944 KB |
01-03.txt | AC | 5 ms | 2944 KB |
01-04.txt | AC | 5 ms | 2944 KB |
01-05.txt | AC | 12 ms | 2944 KB |
01-06.txt | AC | 52 ms | 3072 KB |
01-07.txt | AC | 499 ms | 3456 KB |
01-08.txt | AC | 729 ms | 3456 KB |
01-09.txt | AC | 8 ms | 2944 KB |
01-10.txt | AC | 259 ms | 3456 KB |
01-11.txt | AC | 342 ms | 3456 KB |
01-12.txt | AC | 844 ms | 3456 KB |
01-13.txt | AC | 280 ms | 3456 KB |
01-14.txt | AC | 5 ms | 2944 KB |
01-15.txt | AC | 523 ms | 3328 KB |
01-16.txt | AC | 678 ms | 3584 KB |
01-17.txt | AC | 366 ms | 3456 KB |
01-18.txt | AC | 321 ms | 3456 KB |
01-19.txt | AC | 6 ms | 3328 KB |
01-20.txt | AC | 191 ms | 3456 KB |
01-21.txt | AC | 164 ms | 3456 KB |
01-22.txt | AC | 7 ms | 3328 KB |
01-23.txt | AC | 7 ms | 3328 KB |
01-24.txt | AC | 543 ms | 3456 KB |
01-25.txt | AC | 563 ms | 3456 KB |
01-26.txt | AC | 5 ms | 2944 KB |
01-27.txt | AC | 58 ms | 3072 KB |
01-28.txt | AC | 922 ms | 3456 KB |
01-29.txt | AC | 728 ms | 3456 KB |
01-30.txt | AC | 903 ms | 3456 KB |
01-31.txt | AC | 6 ms | 3328 KB |
01-32.txt | AC | 512 ms | 3456 KB |
01-33.txt | AC | 6 ms | 3328 KB |
01-34.txt | AC | 1790 ms | 3456 KB |
01-35.txt | AC | 7 ms | 3328 KB |
01-36.txt | AC | 7 ms | 3328 KB |
01-37.txt | AC | 6 ms | 3328 KB |
01-38.txt | AC | 243 ms | 3456 KB |
01-39.txt | AC | 84 ms | 3456 KB |
01-40.txt | AC | 161 ms | 3456 KB |
01-41.txt | AC | 40 ms | 3456 KB |
01-42.txt | AC | 40 ms | 3456 KB |
01-43.txt | AC | 40 ms | 3584 KB |
01-44.txt | AC | 40 ms | 3456 KB |
01-45.txt | AC | 40 ms | 3456 KB |
01-46.txt | AC | 40 ms | 3456 KB |
02-01.txt | TLE | 4212 ms | 184960 KB |
02-02.txt | TLE | 4212 ms | 186240 KB |
02-03.txt | TLE | 4212 ms | 190848 KB |
02-04.txt | TLE | 4212 ms | 184960 KB |
02-05.txt | AC | 1058 ms | 185984 KB |
02-06.txt | AC | 487 ms | 185856 KB |
02-07.txt | TLE | 4212 ms | 188416 KB |
02-08.txt | TLE | 4212 ms | 188544 KB |
02-09.txt | TLE | 4212 ms | 188544 KB |
02-10.txt | TLE | 4212 ms | 188544 KB |
02-11.txt | TLE | 4212 ms | 188544 KB |
02-12.txt | TLE | 4213 ms | 188544 KB |
sample-01.txt | AC | 5 ms | 2944 KB |
sample-02.txt | AC | 5 ms | 2944 KB |