답안 #564607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564607 2022-05-19T11:51:21 Z 1zaid1 Building Skyscrapers (CEOI19_skyscrapers) C++17
8 / 100
169 ms 75776 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 2e6 + 5, MOD = 1e9+7;
struct point {int x, y, i;};
int vis[M], cnt, nig[M];
vector<int> node[M], ar;
int lca[M][30], d[M];
 
void dfs2(int u) {
    vis[u] = true;
    for (int v:node[u]) {
        if (!vis[v]) {
            d[v] = d[u]+1;
            lca[v][0] = u;
            for (int i = 1; i <= 20; i++) {
                lca[v][i] = lca[lca[v][i-1]][i-1];
            }
 
            dfs2(v);
        }
    }
}
 
int get(int a, int b) {
    if (d[a] < d[b]) swap(a, b);
    int l = 0;
    while (d[a]-d[b] > 0) {
        if ((d[a]-d[b])&(1<<l)) a = lca[a][l];
        l++;
    }
 
    l = 20;
    while (a != b) {
        while (l >= 0 && lca[a][l] == lca[b][l]) l--;
        if (l < 0) return lca[a][0];
        a = lca[a][l];
        b = lca[b][l];
    } return a;
}

vector<int> ans;
void dfs(int s) {
    vis[s] = true;
    int mx = 0;
    for (int i:node[s]) {
        if (vis[i]) {
            mx = max(mx, d[i]+d[s]-2*d[get(i, s)] - 1);
        }
    }

    if (mx&&!nig[s]) {
        nig[s] = mx;
        vis[s] = 0;
        ar.push_back(s);
    } else {
        cnt++;
        ans.push_back(s);
        for (int i:node[s]) if (!vis[i] && !nig[i]) dfs(i);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    
    int n, t;
    cin >> n >> t;

    vector<point> v(n);
    for (auto&i:v) cin >> i.x >> i.y;
    int ind = 1; for (auto&i:v) i.i = ind++;

    vector<point> p;
    sort(v.begin(), v.end(), [](point a, point b){if (a.y == b.y) return a.x < b.x; return a.y < b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || v[i].y == v[i-1].y)) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if (a.x == b.x) return a.y < b.y; return a.x < b.x;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || v[i].x == v[i-1].x)) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].y+1 == p[j].y) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if ((a.x+a.y) == (b.x+b.y)) return a.x < b.x; return a.x+a.y < b.x+b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || (v[i].x+v[i].y) == (v[i-1].x+v[i-1].y))) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if ((a.x-a.y) == (b.x-b.y)) return a.x < b.x; return a.x-a.y < b.x-b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || (v[i].x-v[i].y) == (v[i-1].x-v[i-1].y))) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }

    dfs2(1);
    for (int i = 1; i <= n; i++) vis[i] = 0;
    dfs(1);
    while (ar.size()) {
        sort(ar.begin(), ar.end(), [](int a, int b) {return nig[a] < nig[b];});
        vector<int> tmp = {};
        swap(ar, tmp);
        for (int i:tmp) dfs(i);
    }
    if (cnt >= n) {
        cout << "YES" << endl;
        for (int i:ans) cout << i << endl;
    } else cout << "NO" << endl;

    return 0;
}

/*
3 2
0 0
0 1
0 2
*/

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:83:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:101:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:119:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:137:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB ans=YES N=1
2 Correct 23 ms 47256 KB ans=YES N=4
3 Correct 23 ms 47196 KB ans=NO N=4
4 Correct 24 ms 47444 KB ans=YES N=5
5 Correct 24 ms 47316 KB ans=YES N=9
6 Correct 24 ms 47280 KB ans=YES N=5
7 Correct 24 ms 47204 KB ans=NO N=9
8 Correct 24 ms 47188 KB ans=NO N=10
9 Correct 24 ms 47316 KB ans=YES N=10
10 Correct 27 ms 47220 KB ans=YES N=10
11 Correct 25 ms 47304 KB ans=YES N=10
12 Correct 25 ms 47308 KB ans=YES N=9
13 Correct 23 ms 47288 KB ans=YES N=9
14 Correct 24 ms 47316 KB ans=YES N=8
15 Correct 24 ms 47188 KB ans=YES N=8
16 Correct 24 ms 47252 KB ans=NO N=2
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB ans=YES N=1
2 Correct 23 ms 47256 KB ans=YES N=4
3 Correct 23 ms 47196 KB ans=NO N=4
4 Correct 24 ms 47444 KB ans=YES N=5
5 Correct 24 ms 47316 KB ans=YES N=9
6 Correct 24 ms 47280 KB ans=YES N=5
7 Correct 24 ms 47204 KB ans=NO N=9
8 Correct 24 ms 47188 KB ans=NO N=10
9 Correct 24 ms 47316 KB ans=YES N=10
10 Correct 27 ms 47220 KB ans=YES N=10
11 Correct 25 ms 47304 KB ans=YES N=10
12 Correct 25 ms 47308 KB ans=YES N=9
13 Correct 23 ms 47288 KB ans=YES N=9
14 Correct 24 ms 47316 KB ans=YES N=8
15 Correct 24 ms 47188 KB ans=YES N=8
16 Correct 24 ms 47252 KB ans=NO N=2
17 Correct 25 ms 47244 KB ans=YES N=17
18 Correct 24 ms 47308 KB ans=YES N=25
19 Incorrect 25 ms 47276 KB Added cell 95 (2,-4) not reachable from infinity
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB ans=YES N=1
2 Correct 23 ms 47256 KB ans=YES N=4
3 Correct 23 ms 47196 KB ans=NO N=4
4 Correct 24 ms 47444 KB ans=YES N=5
5 Correct 24 ms 47316 KB ans=YES N=9
6 Correct 24 ms 47280 KB ans=YES N=5
7 Correct 24 ms 47204 KB ans=NO N=9
8 Correct 24 ms 47188 KB ans=NO N=10
9 Correct 24 ms 47316 KB ans=YES N=10
10 Correct 27 ms 47220 KB ans=YES N=10
11 Correct 25 ms 47304 KB ans=YES N=10
12 Correct 25 ms 47308 KB ans=YES N=9
13 Correct 23 ms 47288 KB ans=YES N=9
14 Correct 24 ms 47316 KB ans=YES N=8
15 Correct 24 ms 47188 KB ans=YES N=8
16 Correct 24 ms 47252 KB ans=NO N=2
17 Correct 25 ms 47244 KB ans=YES N=17
18 Correct 24 ms 47308 KB ans=YES N=25
19 Incorrect 25 ms 47276 KB Added cell 95 (2,-4) not reachable from infinity
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47380 KB ans=NO N=1934
2 Correct 25 ms 47828 KB ans=NO N=1965
3 Incorrect 26 ms 48060 KB Added cell 1634 (359,243) not reachable from infinity
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB ans=YES N=1
2 Correct 23 ms 47256 KB ans=YES N=4
3 Correct 23 ms 47196 KB ans=NO N=4
4 Correct 24 ms 47444 KB ans=YES N=5
5 Correct 24 ms 47316 KB ans=YES N=9
6 Correct 24 ms 47280 KB ans=YES N=5
7 Correct 24 ms 47204 KB ans=NO N=9
8 Correct 24 ms 47188 KB ans=NO N=10
9 Correct 24 ms 47316 KB ans=YES N=10
10 Correct 27 ms 47220 KB ans=YES N=10
11 Correct 25 ms 47304 KB ans=YES N=10
12 Correct 25 ms 47308 KB ans=YES N=9
13 Correct 23 ms 47288 KB ans=YES N=9
14 Correct 24 ms 47316 KB ans=YES N=8
15 Correct 24 ms 47188 KB ans=YES N=8
16 Correct 24 ms 47252 KB ans=NO N=2
17 Correct 25 ms 47244 KB ans=YES N=17
18 Correct 24 ms 47308 KB ans=YES N=25
19 Incorrect 25 ms 47276 KB Added cell 95 (2,-4) not reachable from infinity
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 74304 KB ans=NO N=66151
2 Correct 59 ms 50372 KB ans=NO N=64333
3 Incorrect 160 ms 75776 KB Added cell 69308 (20,-288) not reachable from infinity
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47380 KB ans=NO N=1934
2 Correct 25 ms 47828 KB ans=NO N=1965
3 Incorrect 26 ms 48060 KB Added cell 1634 (359,243) not reachable from infinity
4 Halted 0 ms 0 KB -