#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
map<pair<int, int>, int> mp;
map<pair<int, int>, bool> mp2;
int n, t, j;
int a[1500001];
bool vis[1500001];
int xi[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int yi[8] = {-1, 1, 0, 0, -1, 1, -1, 1};
bool check(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < n;
}
bool check2(int x, int y) {
mp2[{x, y}] = 1;
bool b = 0;
for(int i = 0; i < 4; i++) {
int xx = x + xi[i];
int yy = y + yi[i];
if(!check(xx, yy))
b = 1;
else if(!mp2[{xx, yy}] && mp[{xx, yy}] != n + 1)
b |= check2(xx, yy);
if(b)
return 1;
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> t;
vector<pair<int, int>> v;
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
v.push_back({x, y});
mp[{x, y}] = i + 1;
}
vector<int> vec;
vec.push_back(0);
vis[0] = 1;
int k = 0;
j = 0;
int sz = 1;
while(k < sz) {
int ind = vec[k++];
int x = v[ind].first, y = v[ind].second;
mp2.clear();
if(!check2(x, y)) {
if(k == sz)
break;
vec.push_back(ind);
continue;
}
mp[{x, y}] = n + 1;
a[j++] = ind;
for(int i = 0; i < 8; i++) {
int xx = x + xi[i];
int yy = y + yi[i];
if(check(xx, yy) && mp[{xx, yy}] && mp[{xx, yy}] != n + 1 && !vis[mp[{xx, yy}] - 1]) {
vis[mp[{xx, yy}] - 1] = 1;
vec.push_back(mp[{xx, yy}] - 1);
sz++;
}
}
}
if(j != n) {
cout << "NO";
return 0;
}
cout << "YES\n";
for(int i = 0; i < n; i++)
cout << a[i] + 1 << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
340 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
340 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
340 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
340 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
340 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
340 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
787 ms |
6056 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 595) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
340 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
340 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
5460 KB |
ans=NO N=66151 |
2 |
Correct |
33 ms |
4860 KB |
ans=NO N=64333 |
3 |
Incorrect |
33 ms |
5444 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
787 ms |
6056 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 595) |
4 |
Halted |
0 ms |
0 KB |
- |