제출 #564854

#제출 시각아이디문제언어결과실행 시간메모리
564854RealSnakeBuilding Skyscrapers (CEOI19_skyscrapers)C++14
54 / 100
359 ms39992 KiB
#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;
int a[150001];
bool vis[150001];
map<pair<int, int>, int> mp;
int xi[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int yi[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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;
    }
    pair<int, int> p = *max_element(v.begin(), v.end());
    priority_queue<pair<int, int>> pq;
    pq.push(p);
    vis[mp[p] - 1] = 1;
    int j = 0;
    while(!pq.empty()) {
        int x = pq.top().first, y = pq.top().second;
        pq.pop();
        a[j++] = mp[{x, y}];
        for(int i = 0; i < 8; i++) {
            int xx = x + xi[i];
            int yy = y + yi[i];
            if(mp[{xx, yy}] && !vis[mp[{xx, yy}] - 1]) {
                vis[mp[{xx, yy}] - 1] = 1;
                pq.push({xx, yy});
            }
        }
    }
    if(j != n) {
        cout << "NO";
        return 0;
    }
    cout << "YES\n";
    for(int i = 0; i < n; i++)
        cout << a[i] << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...