#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 32768
#define INF 100000000000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n, t;
cin >> n >> t;
map<pair<long long,long long>,long long> mp;
long long cnt = 1;
bool check[n+1] = {};
vector<int> ans;
priority_queue<pair<long long,long long>> pq;
for(int i = 0; i < n; i++)
{
long long a, b;
cin >> a >> b;
if(i == 0)
{
pq.push({a,b});
}
mp[{a,b}] = cnt;
cnt++;
}
while(!pq.empty())
{
pair<long long ,long long> tp = pq.top();
long long x = tp.first, y = tp.second;
ans.push_back(mp[{x,y}]);
check[mp[{x,y}]] = 1;
pq.pop();
if(mp[{x+1,y}] > 0 && check[mp[{x+1,y}]] == 0)
{
pq.push({x+1,y});
}
if(mp[{x-1,y}] > 0 && check[mp[{x-1,y}]] == 0)
{
pq.push({x-1,y});
}
if(mp[{x,y+1}] > 0 && check[mp[{x,y+1}]] == 0)
{
pq.push({x,y+1});
}
if(mp[{x,y-1}] > 0 && check[mp[{x,y-1}]] == 0)
{
pq.push({x,y-1});
}
if(mp[{x+1,y+1}] > 0 && check[mp[{x+1,y+1}]] == 0)
{
pq.push({x+1,y+1});
}
if(mp[{x-1,y-1}] > 0 && check[mp[{x-1,y-1}]] == 0)
{
pq.push({x-1,y-1});
}
if(mp[{x-1,y+1}] > 0 && check[mp[{x-1,y+1}]] == 0)
{
pq.push({x-1,y+1});
}
if(mp[{x+1,y-1}] > 0 && check[mp[{x+1,y-1}]] == 0)
{
pq.push({x+1,y-1});
}
}
bool ok = true;
for(int i = 1; i <= n; i++)
{
if(check[i] == 0)
{
ok = false;
break;
}
}
if(ok)
{
cout << "YES" << endl;
for(int i = 0; i < ans.size(); i++)
cout << ans[i] << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Incorrect |
1 ms |
212 KB |
Each cell must be removed exactly once |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Incorrect |
1 ms |
212 KB |
Each cell must be removed exactly once |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Incorrect |
1 ms |
212 KB |
Each cell must be removed exactly once |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
ans=NO N=1934 |
2 |
Correct |
6 ms |
596 KB |
ans=NO N=1965 |
3 |
Execution timed out |
3614 ms |
548748 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Incorrect |
1 ms |
212 KB |
Each cell must be removed exactly once |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3558 ms |
287604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
ans=NO N=1934 |
2 |
Correct |
6 ms |
596 KB |
ans=NO N=1965 |
3 |
Execution timed out |
3614 ms |
548748 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |