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>
#define int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
int xx[] = {-1,-1,-1,0,1,1,1,0}, yy[] = {-1,0,1,1,1,0,-1,-1};
signed main(){
boost;
int n,t; cin >> n >> t;
vector<pair<int,pair<int,int>>>d(n);
vector<int>ans;
map<pair<int,int>,int>o;
for(int i = 0; i < n; i++){
cin >> d[i].first >> d[i].second.first;
d[i].second.second = i + 1;
o[{d[i].first,d[i].second.first}] = i + 1;
}
int x = -1e18, y = -1e18, j = 0;
set<pair<int,pair<int,int>>>c;
set<pair<int,int>>a;
for(int i = 0; i < n; i++){
if(d[i].first > x){
x = d[i].first;
y = d[i].second.first;
j = i + 1;
}else if(d[i].first == x && d[i].second.first > y){
x = d[i].first;
y = d[i].second.first;
j = i + 1;
}
a.insert({d[i].first,d[i].second.first});
}
a.erase({x,y});
c.insert({x,{y,j}});
while(c.size()){
auto f = *c.begin();
ans.push_back(f.second.second);
c.erase(c.begin());
for(int i = 0; i < 8; i++){
int aa = f.first + xx[i], b = f.second.first + yy[i];
if(!a.count({aa,b})) continue;
c.insert({aa,{b,o[{aa,b}]}});
a.erase({aa,b});
}
}
if(ans.size() < n){
cout << "NO";
return 0;
}
cout << "YES" << endl;
for(int i = 0; i < n ;i++){
cout << ans[i] << endl;
}
return 0;
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:56:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
56 | if(ans.size() < 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... |