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 <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
using namespace std;
typedef pair <int, int> ii;
struct cmp1 {
bool operator()(const ii &a, const ii &b) {
if (a.first != b.first) {
return a.first < b.first;
}
return a.second < b.second;
}
};
struct cmp2 {
bool operator()(const ii &a, const ii &b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
};
int n;
bool ok = 1;
set <ii, cmp1> row;
set <ii, cmp2> col;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x != -1) {
row.insert({i, x + 1});
col.insert({i, x + 1});
}
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x == -1) {
auto it = row.upper_bound({i, -1});
if (it != row.end() && it->first == i) {
ok = 0;
}
continue;
}
x = n - x;
auto it = row.upper_bound({i, x});
if (it != row.end() && it->first == i) {
ok = 0;
}
row.insert({i, x});
col.insert({i, x});
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x; x++;
if (x == -1) {
auto it = col.upper_bound({-1, i});
if (it != col.end() && it->second == i) {
ok = 0;
}
continue;
}
auto it = col.upper_bound({x, i});
if (it != col.end() && it->second == i) {
ok = 0;
}
row.insert({x, i});
col.insert({x, i});
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x == -1) {
auto it = col.upper_bound({-1, i});
if (it != col.end() && it->second == i) {
ok = 0;
}
continue;
}
x = n - x;
auto it = col.upper_bound({x, i});
if (it != col.end() && it->second == i) {
ok = 0;
}
row.insert({x, i});
col.insert({x, i});
}
if (ok) {
cout << "DA" << endl;
} else {
cout << "NE" << endl;
}
return 0;
}
# | 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... |