# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92449 | ltomic | Kocka (COCI18_kocka) | C++14 | 487 ms | 51236 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <set>
#include <cstdlib>
using namespace std;
const int MAXN = 1e5+5;
set<int> s[2][MAXN];
int l[MAXN], r[MAXN], u[MAXN], d[MAXN];
int n;
void no(int id) {
printf("NE\n");
exit(0);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", l+i);
if (l[i] == -1) continue;
s[0][i].insert(l[i]);
s[1][l[i]].insert(i);
}
for (int i = 0; i < n; ++i) {
scanf("%d", r+i);
if (r[i] == -1) continue;
s[0][i].insert(n-r[i]-1);
s[1][n-r[i]-1].insert(i);
}
for (int i = 0; i < n; ++i) {
scanf("%d", u+i);
if (u[i] == -1) continue;
s[1][i].insert(u[i]);
s[0][u[i]].insert(i);
}
for (int i = 0; i < n; ++i) {
scanf("%d", d+i);
if (d[i] == -1) continue;
s[0][n-d[i]-1].insert(i);
s[1][i].insert(n-d[i]-1);
}
/*
for (int i = 0; i < 2; ++i) {
printf("DIR :%d\n", i);
for (int j = 0; j < n; ++j) {
printf("j: %d\n", j);
for (int k: s[i][j]) printf("%d ", k);
printf("\n");
}
printf("\n");
}*/
for (int i = 0; i < n; ++i) {
if (l[i] == -1) {
if (s[0][i].size() > 0) no(0);
} else {
if (s[0][i].size() == 0 || l[i] != *s[0][i].begin()) no(1);
}
if (u[i] == -1) {
if (s[1][i].size() > 0) no(2);
} else if (s[1][i].size() == 0 || u[i] != *s[1][i].begin()) no(3);
if (r[i] == -1) {
if (s[0][i].size() > 0) no(4);
} else if (s[0][i].size() == 0 || r[i] != n-1-*(--s[0][i].end())) no(5);
if (d[i] == -1) {
if (s[1][i].size() > 0) no(6);
} else if (s[1][i].size() == 0 || d[i] != n-1-*(--s[1][i].end())) no(7);
}
printf("DA\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |