답안 #566156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566156 2022-05-21T23:00:39 Z shrimb Building Skyscrapers (CEOI19_skyscrapers) C++17
51 / 100
3500 ms 111564 KB
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx,avx2,fma")

#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;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 150001;
const int dx[] = {1, 1, 0, -1, -1, -1,  0,  1};
const int dy[] = {0, 1, 1,  1,  0, -1, -1, -1};
const int inv[] = {4, 5, 6, 7, 0, 1, 2, 3};
struct cell;

int n, t, ID;
cell* Find (cell *x);
void check (cell *c);
void Union (cell *a, cell *b);
bitset<maxn> deleted;

map<pair<int,int>, cell*> cells;

struct cell {
    bool full = 0, out = 0;
    int x, y, ind;
    cell* adj[8], *parent = this, *prev = nullptr;
    vector<cell*> vec;
    cell(int a, int b, bool f) {
        // cerr << endl << a <<  " " << b << endl;
        full = f;
        x = a, y = b;
        cells[{x, y}] = this;
        if (f == 0) vec = {this};
        else ind = ID;
        for (int d = 0 ; d < 8 ; d++) {
            int u = x + dx[d];
            int v = y + dy[d];
            auto it = cells.find({u, v});
            if (it != cells.end()) {
                adj[d] = it -> second;
                it -> second -> adj[inv[d]] = this;
            }
            else  adj[d] = nullptr;
        }
        if (f == 0) {
            for (int d = 0 ; d < 8 ; d += 2) {
                if (adj[d]) {
                    if (!adj[d] -> full) Union(this, adj[d]);
                }
            }
            for (int d = 0 ; d < 8 ; d++) {
                if (adj[d] and adj[d] -> full) check(adj[d]);
            }
        }
    }
};
cell* inp[maxn];

struct cmp {
    bool operator () (cell *a, cell *b) const {
        return a -> ind > b -> ind;
    }
};

set<cell*,cmp> expendable;


cell* Find (cell *x) {
    return x == x -> parent ? x : x -> parent = Find(x -> parent);
}

void check (cell *c) {
    bool articulation = 0, isout = 0, sep = 0;
    // cerr << c -> ind << " " << articulation <<  endl;
    for (int i = 0 ; i < 8 ; i++) if (!c -> adj[i]) return;
    for (int i = 0 ; i < 8 ; i+=2) {
        if (!c -> adj[i] -> full) isout |= Find(c -> adj[i]) -> out;
    }
    if (!isout) {
        expendable.erase(c);
        return;
    }
    // cerr << c -> x << " " << c -> y << endl;
    for (int _d = 0 ; _d < 9 ; _d++) {
        int d = (_d == 8 ? 0 : _d);
        if (c -> adj[d] -> full) {
            sep = 1;
            continue;
        }
        if (d & 1) continue;
        auto cmp = Find(c -> adj[d]);
        // cerr << "kfdjasdd: " << d << " " << cmp -> out << " | ";
        if (cmp -> prev and sep == 1) {
            // cerr << cmp -> prev -> x << " " << cmp -> prev -> y << endl;
            bool bad = 0;
            for (int __d = _d ; !bad ; __d++) {
                int d2 = __d % 8;
                if (c -> adj[d2] == cmp -> prev) break;
                if (c -> adj[d2] -> full) bad = 1;
            }
            if (bad) {
                articulation = 1;
                break;
            }
        }
        // cerr << endl;
        cmp -> prev = c -> adj[d];
        sep = 0;
    }
    // cerr << articulation << endl;
    for (int d = 0 ; d < 8 ; d++) {
        if (!c -> adj[d] -> full) {
            Find(c -> adj[d]) -> prev = nullptr;
            // cerr << Find(c -> adj[d]) -> prev << endl;
        }
    }
    // cerr << c -> x << " " << c -> y << " " << isout << " ..." << articulation << endl;
    if (!articulation) expendable.insert(c);
    else expendable.erase(c);
}

void Union (cell *a, cell *b) {
    cell *x = Find(a), *y = Find(b);
    if (x == y) return;
    if (x -> vec.size() > y -> vec.size()) swap(x, y);
    x -> parent = y;
    y -> out |= x -> out;
    for (auto &i : x -> vec) {
        y -> vec.push_back(i);
        for (int d = 0 ; d < 8 ; d++) if (i -> adj[d] and i -> adj[d] -> full) check(i -> adj[d]);
    }
    x -> vec.clear();
}

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> t;
    for (int i = 0 ; i < n ; i++) {
        ID = i;
        int x, y;
        cin >> x >> y;
        inp[i] = new cell(x, y, 1);
    }
    int idx = 0;
    for (int i = 0 ; i < n ; i++) {
        if (inp[i] -> x < inp[idx] -> x) idx = i;
        else if (inp[i] -> x == inp[idx] -> x and inp[i] -> y < inp[idx] -> y) idx = i;
    }
    inp[idx] -> adj[4] = new cell(inp[idx] -> x + dx[4], inp[idx] -> y + dy[4], 0);
    inp[idx] -> adj[4] -> out = 1;
    // cerr << idx << endl;
    for (int i = 0 ; i < n ; i++) {
        // cerr << i << ": ";
        for (int d = 0 ; d < 8 ; d++) {
            // cerr << d << " ";
            if (!inp[i] -> adj[d]) {
                new cell(inp[i] -> x + dx[d], inp[i] -> y + dy[d], 0);
            }
        }
    }
    // assert(0);
    if (n > 1) {
        for (int i = 0 ; i < n ; i++) {
            bool good = 0;
            for (int d = 0 ; d < 8 ; d++) {
                if (inp[i] -> adj[d] -> full) good = 1;
            }
            if (!good) {
                cout << "NO\n";
                return 0;
            }
        }
    }

    // for (int i = 0 ; i < n ; i++) {
    //     for (auto j : inp[i] -> adj) {
    //         if (!j -> full)
    //         for (auto k : j -> adj) {
    //             if (k and !k -> full) Union(j, k);
    //         }
    //     }
    // }

    for (int i = 0 ; i < n ; i++) check(inp[i]);
    cout << "YES\n";
    vector<int> ans;
    // cerr << "alkjdaskldjaslkjlkadjlkasjdlkasj\n";
    while (expendable.size()) {
        for (int i = 0 ; i < n ; i++) {
            if (!deleted[i]) check(inp[i]);
        }
        auto cur = *expendable.begin();
        expendable.erase(expendable.begin());
        ans.push_back(cur -> ind + 1);
        deleted[cur -> ind] = 1;
        new cell(cur -> x, cur -> y, 0);
    }
    reverse(ans.begin(), ans.end());
    for (int i:  ans) cout << i << endl;
}

/*
9
2
0 0 0 1
1 -1 2 -1
3 0 3 1
1 2 2 2
1 0
*/

Compilation message

skyscrapers.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 340 KB ans=YES N=5
7 Correct 1 ms 340 KB ans=NO N=9
8 Correct 1 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 340 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 332 KB ans=YES N=8
15 Correct 1 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 340 KB ans=YES N=5
7 Correct 1 ms 340 KB ans=NO N=9
8 Correct 1 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 340 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 332 KB ans=YES N=8
15 Correct 1 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 340 KB ans=YES N=17
18 Correct 1 ms 340 KB ans=YES N=25
19 Correct 2 ms 384 KB ans=YES N=100
20 Correct 4 ms 340 KB ans=YES N=185
21 Correct 2 ms 592 KB ans=NO N=174
22 Correct 1 ms 340 KB ans=YES N=90
23 Correct 1 ms 332 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 3 ms 336 KB ans=YES N=183
26 Correct 3 ms 424 KB ans=YES N=188
27 Correct 3 ms 460 KB ans=YES N=183
28 Correct 3 ms 340 KB ans=YES N=189
29 Correct 4 ms 340 KB ans=YES N=200
30 Correct 4 ms 464 KB ans=YES N=190
31 Correct 4 ms 428 KB ans=YES N=187
32 Correct 4 ms 468 KB ans=YES N=187
33 Correct 4 ms 464 KB ans=YES N=182
34 Correct 4 ms 468 KB ans=YES N=184
35 Correct 4 ms 464 KB ans=YES N=188
36 Correct 5 ms 464 KB ans=YES N=181
37 Correct 4 ms 520 KB ans=YES N=188
38 Correct 4 ms 468 KB ans=YES N=191
39 Correct 3 ms 464 KB ans=YES N=196
40 Correct 3 ms 452 KB ans=YES N=196
41 Correct 3 ms 452 KB ans=YES N=196
42 Correct 3 ms 468 KB ans=YES N=196
43 Correct 4 ms 472 KB ans=YES N=195
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 340 KB ans=YES N=5
7 Correct 1 ms 340 KB ans=NO N=9
8 Correct 1 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 340 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 332 KB ans=YES N=8
15 Correct 1 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 340 KB ans=YES N=17
18 Correct 1 ms 340 KB ans=YES N=25
19 Correct 2 ms 384 KB ans=YES N=100
20 Correct 4 ms 340 KB ans=YES N=185
21 Correct 2 ms 592 KB ans=NO N=174
22 Correct 1 ms 340 KB ans=YES N=90
23 Correct 1 ms 332 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 3 ms 336 KB ans=YES N=183
26 Correct 3 ms 424 KB ans=YES N=188
27 Correct 3 ms 460 KB ans=YES N=183
28 Correct 3 ms 340 KB ans=YES N=189
29 Correct 4 ms 340 KB ans=YES N=200
30 Correct 4 ms 464 KB ans=YES N=190
31 Correct 4 ms 428 KB ans=YES N=187
32 Correct 4 ms 468 KB ans=YES N=187
33 Correct 4 ms 464 KB ans=YES N=182
34 Correct 4 ms 468 KB ans=YES N=184
35 Correct 4 ms 464 KB ans=YES N=188
36 Correct 5 ms 464 KB ans=YES N=181
37 Correct 4 ms 520 KB ans=YES N=188
38 Correct 4 ms 468 KB ans=YES N=191
39 Correct 3 ms 464 KB ans=YES N=196
40 Correct 3 ms 452 KB ans=YES N=196
41 Correct 3 ms 452 KB ans=YES N=196
42 Correct 3 ms 468 KB ans=YES N=196
43 Correct 4 ms 472 KB ans=YES N=195
44 Correct 17 ms 4436 KB ans=NO N=1934
45 Correct 10 ms 1748 KB ans=NO N=1965
46 Correct 183 ms 1208 KB ans=YES N=1824
47 Correct 220 ms 1260 KB ans=YES N=1981
48 Correct 170 ms 1080 KB ans=YES N=1814
49 Correct 269 ms 1240 KB ans=YES N=1854
50 Correct 179 ms 1184 KB ans=YES N=1831
51 Correct 231 ms 1228 KB ans=YES N=2000
52 Correct 267 ms 1412 KB ans=YES N=1847
53 Correct 264 ms 1540 KB ans=YES N=1819
54 Correct 217 ms 1380 KB ans=YES N=1986
55 Correct 338 ms 1996 KB ans=YES N=2000
56 Correct 261 ms 2232 KB ans=YES N=1834
57 Correct 279 ms 2176 KB ans=YES N=1860
58 Correct 297 ms 2216 KB ans=YES N=1898
59 Correct 277 ms 1864 KB ans=YES N=1832
60 Correct 258 ms 2792 KB ans=YES N=1929
61 Correct 262 ms 1480 KB ans=YES N=1919
62 Correct 286 ms 2028 KB ans=YES N=1882
63 Correct 258 ms 2772 KB ans=YES N=1922
64 Correct 286 ms 1628 KB ans=YES N=1989
65 Correct 197 ms 1912 KB ans=YES N=1978
66 Correct 231 ms 1984 KB ans=YES N=1867
67 Correct 335 ms 1840 KB ans=YES N=1942
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4360 KB ans=NO N=1934
2 Correct 8 ms 1748 KB ans=NO N=1965
3 Correct 178 ms 1120 KB ans=YES N=1824
4 Correct 234 ms 1228 KB ans=YES N=1981
5 Correct 165 ms 1064 KB ans=YES N=1814
6 Correct 233 ms 1416 KB ans=YES N=1854
7 Correct 182 ms 1076 KB ans=YES N=1831
8 Correct 229 ms 1280 KB ans=YES N=2000
9 Correct 272 ms 1412 KB ans=YES N=1847
10 Correct 257 ms 1596 KB ans=YES N=1819
11 Correct 219 ms 1160 KB ans=YES N=1986
12 Correct 340 ms 2100 KB ans=YES N=2000
13 Correct 257 ms 2236 KB ans=YES N=1834
14 Correct 294 ms 2196 KB ans=YES N=1860
15 Correct 284 ms 2252 KB ans=YES N=1898
16 Correct 277 ms 1876 KB ans=YES N=1832
17 Correct 266 ms 2616 KB ans=YES N=1929
18 Correct 270 ms 1488 KB ans=YES N=1919
19 Correct 307 ms 2004 KB ans=YES N=1882
20 Correct 243 ms 2804 KB ans=YES N=1922
21 Correct 298 ms 1452 KB ans=YES N=1989
22 Correct 201 ms 1916 KB ans=YES N=1978
23 Correct 234 ms 2068 KB ans=YES N=1867
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 0 ms 212 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 340 KB ans=YES N=5
7 Correct 1 ms 340 KB ans=NO N=9
8 Correct 1 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 340 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 332 KB ans=YES N=8
15 Correct 1 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 340 KB ans=YES N=17
18 Correct 1 ms 340 KB ans=YES N=25
19 Correct 2 ms 384 KB ans=YES N=100
20 Correct 4 ms 340 KB ans=YES N=185
21 Correct 2 ms 592 KB ans=NO N=174
22 Correct 1 ms 340 KB ans=YES N=90
23 Correct 1 ms 332 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 3 ms 336 KB ans=YES N=183
26 Correct 3 ms 424 KB ans=YES N=188
27 Correct 3 ms 460 KB ans=YES N=183
28 Correct 3 ms 340 KB ans=YES N=189
29 Correct 4 ms 340 KB ans=YES N=200
30 Correct 4 ms 464 KB ans=YES N=190
31 Correct 4 ms 428 KB ans=YES N=187
32 Correct 4 ms 468 KB ans=YES N=187
33 Correct 4 ms 464 KB ans=YES N=182
34 Correct 4 ms 468 KB ans=YES N=184
35 Correct 4 ms 464 KB ans=YES N=188
36 Correct 5 ms 464 KB ans=YES N=181
37 Correct 4 ms 520 KB ans=YES N=188
38 Correct 4 ms 468 KB ans=YES N=191
39 Correct 3 ms 464 KB ans=YES N=196
40 Correct 3 ms 452 KB ans=YES N=196
41 Correct 3 ms 452 KB ans=YES N=196
42 Correct 3 ms 468 KB ans=YES N=196
43 Correct 4 ms 472 KB ans=YES N=195
44 Correct 17 ms 4436 KB ans=NO N=1934
45 Correct 10 ms 1748 KB ans=NO N=1965
46 Correct 183 ms 1208 KB ans=YES N=1824
47 Correct 220 ms 1260 KB ans=YES N=1981
48 Correct 170 ms 1080 KB ans=YES N=1814
49 Correct 269 ms 1240 KB ans=YES N=1854
50 Correct 179 ms 1184 KB ans=YES N=1831
51 Correct 231 ms 1228 KB ans=YES N=2000
52 Correct 267 ms 1412 KB ans=YES N=1847
53 Correct 264 ms 1540 KB ans=YES N=1819
54 Correct 217 ms 1380 KB ans=YES N=1986
55 Correct 338 ms 1996 KB ans=YES N=2000
56 Correct 261 ms 2232 KB ans=YES N=1834
57 Correct 279 ms 2176 KB ans=YES N=1860
58 Correct 297 ms 2216 KB ans=YES N=1898
59 Correct 277 ms 1864 KB ans=YES N=1832
60 Correct 258 ms 2792 KB ans=YES N=1929
61 Correct 262 ms 1480 KB ans=YES N=1919
62 Correct 286 ms 2028 KB ans=YES N=1882
63 Correct 258 ms 2772 KB ans=YES N=1922
64 Correct 286 ms 1628 KB ans=YES N=1989
65 Correct 197 ms 1912 KB ans=YES N=1978
66 Correct 231 ms 1984 KB ans=YES N=1867
67 Correct 335 ms 1840 KB ans=YES N=1942
68 Correct 255 ms 23616 KB ans=NO N=66151
69 Correct 874 ms 111564 KB ans=NO N=64333
70 Execution timed out 3593 ms 16236 KB Time limit exceeded
71 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 23612 KB ans=NO N=66151
2 Correct 912 ms 110948 KB ans=NO N=64333
3 Execution timed out 3586 ms 15720 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4360 KB ans=NO N=1934
2 Correct 8 ms 1748 KB ans=NO N=1965
3 Correct 178 ms 1120 KB ans=YES N=1824
4 Correct 234 ms 1228 KB ans=YES N=1981
5 Correct 165 ms 1064 KB ans=YES N=1814
6 Correct 233 ms 1416 KB ans=YES N=1854
7 Correct 182 ms 1076 KB ans=YES N=1831
8 Correct 229 ms 1280 KB ans=YES N=2000
9 Correct 272 ms 1412 KB ans=YES N=1847
10 Correct 257 ms 1596 KB ans=YES N=1819
11 Correct 219 ms 1160 KB ans=YES N=1986
12 Correct 340 ms 2100 KB ans=YES N=2000
13 Correct 257 ms 2236 KB ans=YES N=1834
14 Correct 294 ms 2196 KB ans=YES N=1860
15 Correct 284 ms 2252 KB ans=YES N=1898
16 Correct 277 ms 1876 KB ans=YES N=1832
17 Correct 266 ms 2616 KB ans=YES N=1929
18 Correct 270 ms 1488 KB ans=YES N=1919
19 Correct 307 ms 2004 KB ans=YES N=1882
20 Correct 243 ms 2804 KB ans=YES N=1922
21 Correct 298 ms 1452 KB ans=YES N=1989
22 Correct 201 ms 1916 KB ans=YES N=1978
23 Correct 234 ms 2068 KB ans=YES N=1867
24 Correct 246 ms 23612 KB ans=NO N=66151
25 Correct 912 ms 110948 KB ans=NO N=64333
26 Execution timed out 3586 ms 15720 KB Time limit exceeded
27 Halted 0 ms 0 KB -