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 "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");
int n, t;
bool vis[11][11];
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) {
for(int i = 0; i < 4; i++) {
int xx = x + xi[i];
int yy = y + yi[i];
if(!check(xx, yy) || !vis[xx][yy])
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});
}
if(n <= 10) {
vector<int> vec;
for(int i = 0; i < n; i++)
vec.push_back(i);
do {
bool yes = 1;
for(int i = 0; i < n; i++) {
int j = vec[i];
int x = v[j].first, y = v[j].second;
vis[x][y] = 1;
for(int j = 0; j < 8; j++) {
if(!i)
break;
int xx = x + xi[j];
int yy = y + yi[j];
if(check(xx, yy) && vis[xx][yy])
break;
if(j == 7) {
yes = 0;
break;
}
}
if(!yes || !check2(x, y)) {
yes = 0;
break;
}
}
if(yes) {
cout << "YES\n";
for(int i : vec)
cout << i + 1 << "\n";
return 0;
}
} while(next_permutation(vec.begin(), vec.end()));
cout << "NO\n";
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |