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;
#define int long long
#define rep(i,a,n) for(int i = a; i<n; i++)
#define per(i,a,n) for(int i = n-1; i>=a; i--)
map<pair<int,int>,bool> vis;
map<pair<int,int>,int> idx;
int n,t;
int max(int a,int b){return (a>b)?a:b;}
int min(int a,int b){return (a<b)?a:b;}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>t;
bool f = false;
pair<int,int> start = make_pair(-1,-1);
rep(i,0,n){
int x,y;
cin>>x>>y;
idx[make_pair(x,y)] = i+1;
vis[make_pair(x,y)] = false;
if(!f || x > start.first)start = make_pair(x,y),f = true;
}
priority_queue<pair<int,int> > pq;
vector<pair<int,int> > res;
pq.push(start);
vis[start] = true;
while(!pq.empty()){
pair<int,int> node = pq.top();
pq.pop();
res.push_back(node);
rep(i,-1,2){
rep(j,-1,2){
if(i==0&&j==0)continue;
pair<int,int> e = node;
e.first += i;
e.second += j;
if(vis.find(e) != vis.end() && !vis[e]){
vis[e] = true;
pq.push(e);
}
}
}
}
bool works = true;
for(auto i:vis){
works &= i.second;
}
if(works){
for(auto i:res){
cout<<idx[i]<<" ";
}
cout<<"\n";
}else{
cout<<"NO\n";
}
}
# | 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... |