Submission #8676889
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N = 333; vector <int> g[N * N]; bool alive_b[N * N]; int pb[N * N], was[N * N]; int it; int start = -1; 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 || pb[u] == start)) { 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])) { pb[u] = v; return true; } } } return false; } bool dfs_finish(int v, int finish) { if (pb[finish] == v) { return true; } start = v; it++; if (dfs(pb[finish])) { pb[finish] = v; return true; } return false; } int what[N * N]; int U[N], D[N], L[N], R[N]; int empty[N][N]; int first_L[N], first_U[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 deg[N * N]; 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++) { for (int j = 0; j < n; j++) { g[cnt].push_back(i * n + j); } what[cnt] = i; deg[cnt] = L[i] + R[i]; first_L[i] = cnt++; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { g[cnt].push_back(j * n + i); } what[cnt] = ~i; deg[cnt] = U[i] + D[i]; first_U[i] = cnt++; } for (int i = 0; i < n * n; i++) { pb[i] = -1; was[i] = -1; } for (int i = 0; i < n * n; i++) { alive_b[i] = true; } for (int i = 0; i < cnt; i++) { for (int j = 0; j < deg[i]; j++) { 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; } int iter = 0; while (iter < n * n) { { for (int i = 0; i < n; i++) { while (L[i] > 0) { int j = cell_L[i]; if (pb[i * n + j] == first_L[i]) { printf("L%d\n", i + 1); L[i]--; take_cell(i, j); ++iter; } else { break; } } while (R[i] > 0) { int j = cell_R[i]; if (pb[i * n + j] == first_L[i]) { printf("R%d\n", i + 1); R[i]--; take_cell(i, j); ++iter; } else { break; } } } for (int j = 0; j < n; j++) { while (U[j] > 0) { int i = cell_U[j]; if (pb[i * n + j] == first_U[j]) { printf("U%d\n", j + 1); U[j]--; take_cell(i, j); ++iter; } else { break; } } while (D[j] > 0) { int i = cell_D[j]; if (pb[i * n + j] == first_U[j]) { printf("D%d\n", j + 1); D[j]--; take_cell(i, j); ++iter; } else { break; } } } } for (int i = 0; i < n; i++) { while (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]--; take_cell(i, j); ++iter; break; } else { break; } } while (R[i] > 0) { int j = cell_R[i]; if (dfs_finish(first_L[i], i * n + j)) { printf("R%d\n", i + 1); R[i]--; take_cell(i, j); ++iter; break; } else { break; } } } for (int j = 0; j < n; j++) { while (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]--; take_cell(i, j); ++iter; break; } else { break; } } while (D[j] > 0) { int i = cell_D[j]; if (dfs_finish(first_U[j], i * n + j)) { printf("D%d\n", j + 1); D[j]--; take_cell(i, j); ++iter; break; } else { break; } } } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | J - Neue Spiel |
User | tourist |
Language | C++14 (GCC 5.4.1) |
Score | 2100 |
Code Size | 5227 Byte |
Status | AC |
Exec Time | 1220 ms |
Memory | 5760 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:84:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:86:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", U + i); ^ ./Main.cpp:89:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", D + i); ^ ./Main.cpp:92:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", L + i); ^ ./Main.cpp:95: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 | 100 / 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, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 3072 KB |
01-02.txt | AC | 2 ms | 3072 KB |
01-03.txt | AC | 2 ms | 3072 KB |
01-04.txt | AC | 2 ms | 3072 KB |
01-05.txt | AC | 2 ms | 3200 KB |
01-06.txt | AC | 2 ms | 3200 KB |
01-07.txt | AC | 3 ms | 3200 KB |
01-08.txt | AC | 3 ms | 3200 KB |
01-09.txt | AC | 2 ms | 3200 KB |
01-10.txt | AC | 3 ms | 3200 KB |
01-11.txt | AC | 3 ms | 3200 KB |
01-12.txt | AC | 3 ms | 3200 KB |
01-13.txt | AC | 3 ms | 3200 KB |
01-14.txt | AC | 2 ms | 3072 KB |
01-15.txt | AC | 2 ms | 3200 KB |
01-16.txt | AC | 3 ms | 3200 KB |
01-17.txt | AC | 3 ms | 3200 KB |
01-18.txt | AC | 3 ms | 3200 KB |
01-19.txt | AC | 2 ms | 3200 KB |
01-20.txt | AC | 3 ms | 3200 KB |
01-21.txt | AC | 3 ms | 3200 KB |
01-22.txt | AC | 2 ms | 3200 KB |
01-23.txt | AC | 2 ms | 3200 KB |
01-24.txt | AC | 3 ms | 3200 KB |
01-25.txt | AC | 3 ms | 3200 KB |
01-26.txt | AC | 2 ms | 3072 KB |
01-27.txt | AC | 2 ms | 3200 KB |
01-28.txt | AC | 3 ms | 3200 KB |
01-29.txt | AC | 3 ms | 3200 KB |
01-30.txt | AC | 3 ms | 3200 KB |
01-31.txt | AC | 2 ms | 3200 KB |
01-32.txt | AC | 3 ms | 3200 KB |
01-33.txt | AC | 2 ms | 3200 KB |
01-34.txt | AC | 3 ms | 3200 KB |
01-35.txt | AC | 2 ms | 3200 KB |
01-36.txt | AC | 2 ms | 3200 KB |
01-37.txt | AC | 2 ms | 3200 KB |
01-38.txt | AC | 2 ms | 3200 KB |
01-39.txt | AC | 2 ms | 3200 KB |
01-40.txt | AC | 3 ms | 3200 KB |
01-41.txt | AC | 3 ms | 3200 KB |
01-42.txt | AC | 2 ms | 3200 KB |
01-43.txt | AC | 2 ms | 3200 KB |
01-44.txt | AC | 2 ms | 3200 KB |
01-45.txt | AC | 2 ms | 3200 KB |
01-46.txt | AC | 3 ms | 3200 KB |
02-01.txt | AC | 980 ms | 5760 KB |
02-02.txt | AC | 1220 ms | 5760 KB |
02-03.txt | AC | 840 ms | 5760 KB |
02-04.txt | AC | 779 ms | 5760 KB |
02-05.txt | AC | 19 ms | 4992 KB |
02-06.txt | AC | 8 ms | 4992 KB |
02-07.txt | AC | 60 ms | 5760 KB |
02-08.txt | AC | 169 ms | 5760 KB |
02-09.txt | AC | 47 ms | 5760 KB |
02-10.txt | AC | 84 ms | 5760 KB |
02-11.txt | AC | 48 ms | 5760 KB |
02-12.txt | AC | 84 ms | 5760 KB |
sample-01.txt | AC | 2 ms | 3072 KB |
sample-02.txt | AC | 2 ms | 3072 KB |