Submission #598996

# Submission time Handle Problem Language Result Execution time Memory
598996 2022-07-19T08:47:18 Z 박상훈(#8456) Building Skyscrapers (CEOI19_skyscrapers) C++17
34 / 100
3500 ms 12324 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct Point{
    int x, y, i;
    Point(){}
    Point(int _x, int _y, int _i): x(_x), y(_y), i(_i) {}
    bool operator<(const Point &P) const{
        return tie(x, y) < tie(P.x, P.y);
    }
}a[150150];
vector<int> ans;
map<int, map<int, int>> mp;
bool visited[150150];
int n, dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};

int bx, by, cnt, b[2020][2020], out[2020][2020], dfn[150150], on[150150], up[150150], cut[150150], ok[150150];

int dfs0(int s){
    visited[s] = 1;
    int ret = 1;
    for (int k=0;k<8;k++){
        int nx = a[s].x + dx[k], ny = a[s].y + dy[k];
        if (mp[nx][ny] && !visited[mp[nx][ny]]){
            ret += dfs0(mp[nx][ny]);
        }
    }
    return ret;
}

void dfs1(int x, int y, int t){
    if (x<0 || x>bx) return;
    if (y<0 || y>by) return;
    if (out[x][y]) return;
    out[x][y] = t;
    if (b[x][y]) return;

    for (int k=0;k<4;k++){
        int nx = x + dx[k], ny = y + dy[k];
        dfs1(nx, ny, t);
    }
}

void compress(){
    vector<int> X, Y;
    for (int i=1;i<=n;i++){
        X.push_back(a[i].x);
        Y.push_back(a[i].y);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());

    for (int i=1;i<=n;i++){
        a[i].x = lower_bound(X.begin(), X.end(), a[i].x) - X.begin() + 1;
        a[i].y = lower_bound(Y.begin(), Y.end(), a[i].y) - Y.begin() + 1;

        b[a[i].x][a[i].y] = i;
        on[i] = 1;
    }

    bx = X.size() + 1;
    by = Y.size() + 1;

    int t = 0;
    for (int i=0;i<=bx;i++){
        for (int j=0;j<=by;j++) if (!out[i][j] && !b[i][j]){
            dfs1(i, j, ++t);
        }
    }

    ok[1] = 1;
}

void dfs(int x, int y, int pa = -1){
    int s = b[x][y];
    visited[s] = 1;
    dfn[s] = ++cnt;
    up[s] = dfn[s];
    cut[s] = 0;

    int child = 0;

    for (int k=0;k<8;k++){
        int nx = x + dx[k], ny = y + dy[k];
        if (!b[nx][ny] || !on[b[nx][ny]]) continue;
        int nnum = b[nx][ny];

        if (visited[nnum] && nnum!=pa){
            up[s] = min(up[s], dfn[nnum]);
        }
        else if (!visited[nnum]){
            child++;
            dfs(nx, ny, s);
            up[s] = min(up[s], up[nnum]);
            if (up[nnum]>=dfn[s] && pa!=-1) cut[s] = 1;
        }
    }

    if (pa==-1 && child>1) cut[s] = 1;

}

void solve(){
    cnt = 0;
    fill(visited+1, visited+n+1, 0);

    for (int i=1;i<=n;i++) if (on[i]) {dfs(a[i].x, a[i].y); break;}
    for (int i=1;i<=n;i++) assert(visited[i]==on[i]);

    /*for (int i=1;i<=n;i++) printf("%d %d %d / ", on[i], out[a[i].x][a[i].y], cut[i]);
    printf("\n");*/

    for (int i=n;i;i--) if (on[i] && ok[out[a[i].x][a[i].y]] && !cut[i]){
        ans.push_back(i);
        on[i] = 0;
        for (int k=0;k<4;k++){
            int nx = a[i].x + dx[k], ny = a[i].y + dy[k];
            if (!b[nx][ny]) ok[out[nx][ny]] = 1;
            else out[nx][ny] = 1;
        }
        return;
    }
    assert(0);
}

int main(){
    int typ;
    scanf("%d %d", &n, &typ);

    for (int i=1;i<=n;i++){
        scanf("%d %d", &a[i].x, &a[i].y);
        a[i].i = i;
        mp[a[i].x][a[i].y] = i;
    }

    if (dfs0(1)!=n) {printf("NO\n"); return 0;}

    compress();
    for (int i=1;i<=n;i++) solve();

    reverse(ans.begin(), ans.end());
    printf("YES\n");
    for (auto &x:ans) printf("%d\n", x);
    return 0;
}

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:131:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |     scanf("%d %d", &n, &typ);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
skyscrapers.cpp:134:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |         scanf("%d %d", &a[i].x, &a[i].y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 340 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 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 0 ms 340 KB ans=YES N=10
11 Correct 0 ms 340 KB ans=YES N=10
12 Correct 0 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 340 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
# Verdict Execution time Memory 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 340 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 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 0 ms 340 KB ans=YES N=10
11 Correct 0 ms 340 KB ans=YES N=10
12 Correct 0 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 340 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 1 ms 340 KB ans=YES N=100
20 Correct 2 ms 468 KB ans=YES N=185
21 Correct 1 ms 340 KB ans=NO N=174
22 Correct 1 ms 596 KB ans=YES N=90
23 Correct 1 ms 340 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 2 ms 468 KB ans=YES N=183
26 Correct 2 ms 468 KB ans=YES N=188
27 Correct 2 ms 468 KB ans=YES N=183
28 Correct 2 ms 468 KB ans=YES N=189
29 Correct 2 ms 468 KB ans=YES N=200
30 Correct 1 ms 468 KB ans=YES N=190
31 Correct 2 ms 468 KB ans=YES N=187
32 Correct 2 ms 596 KB ans=YES N=187
33 Correct 2 ms 596 KB ans=YES N=182
34 Correct 2 ms 724 KB ans=YES N=184
35 Correct 2 ms 852 KB ans=YES N=188
36 Correct 2 ms 724 KB ans=YES N=181
37 Correct 2 ms 724 KB ans=YES N=188
38 Correct 2 ms 1108 KB ans=YES N=191
39 Correct 1 ms 468 KB ans=YES N=196
40 Correct 1 ms 468 KB ans=YES N=196
41 Correct 1 ms 468 KB ans=YES N=196
42 Correct 1 ms 468 KB ans=YES N=196
43 Correct 3 ms 724 KB ans=YES N=195
# Verdict Execution time Memory 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 340 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 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 0 ms 340 KB ans=YES N=10
11 Correct 0 ms 340 KB ans=YES N=10
12 Correct 0 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 340 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 1 ms 340 KB ans=YES N=100
20 Correct 2 ms 468 KB ans=YES N=185
21 Correct 1 ms 340 KB ans=NO N=174
22 Correct 1 ms 596 KB ans=YES N=90
23 Correct 1 ms 340 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 2 ms 468 KB ans=YES N=183
26 Correct 2 ms 468 KB ans=YES N=188
27 Correct 2 ms 468 KB ans=YES N=183
28 Correct 2 ms 468 KB ans=YES N=189
29 Correct 2 ms 468 KB ans=YES N=200
30 Correct 1 ms 468 KB ans=YES N=190
31 Correct 2 ms 468 KB ans=YES N=187
32 Correct 2 ms 596 KB ans=YES N=187
33 Correct 2 ms 596 KB ans=YES N=182
34 Correct 2 ms 724 KB ans=YES N=184
35 Correct 2 ms 852 KB ans=YES N=188
36 Correct 2 ms 724 KB ans=YES N=181
37 Correct 2 ms 724 KB ans=YES N=188
38 Correct 2 ms 1108 KB ans=YES N=191
39 Correct 1 ms 468 KB ans=YES N=196
40 Correct 1 ms 468 KB ans=YES N=196
41 Correct 1 ms 468 KB ans=YES N=196
42 Correct 1 ms 468 KB ans=YES N=196
43 Correct 3 ms 724 KB ans=YES N=195
44 Correct 1 ms 596 KB ans=NO N=1934
45 Correct 1 ms 340 KB ans=NO N=1965
46 Correct 106 ms 1040 KB ans=YES N=1824
47 Correct 125 ms 1108 KB ans=YES N=1981
48 Correct 99 ms 1032 KB ans=YES N=1814
49 Correct 119 ms 1304 KB ans=YES N=1854
50 Correct 114 ms 1024 KB ans=YES N=1831
51 Correct 126 ms 1108 KB ans=YES N=2000
52 Correct 115 ms 1292 KB ans=YES N=1847
53 Correct 99 ms 1396 KB ans=YES N=1819
54 Correct 101 ms 1060 KB ans=YES N=1986
55 Correct 146 ms 1924 KB ans=YES N=2000
56 Correct 123 ms 7380 KB ans=YES N=1834
57 Correct 114 ms 2772 KB ans=YES N=1860
58 Correct 104 ms 3540 KB ans=YES N=1898
59 Correct 117 ms 2148 KB ans=YES N=1832
60 Correct 119 ms 7104 KB ans=YES N=1929
61 Correct 150 ms 1620 KB ans=YES N=1919
62 Correct 106 ms 2772 KB ans=YES N=1882
63 Correct 90 ms 11772 KB ans=YES N=1922
64 Correct 107 ms 6556 KB ans=YES N=1989
65 Correct 62 ms 892 KB ans=YES N=1978
66 Correct 97 ms 11732 KB ans=YES N=1867
67 Correct 134 ms 1812 KB ans=YES N=1942
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB ans=NO N=1934
2 Correct 2 ms 340 KB ans=NO N=1965
3 Correct 102 ms 1040 KB ans=YES N=1824
4 Incorrect 114 ms 1160 KB Contestant's solution is not lexicographically largest at index 1947 (1694 vs 1680)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 340 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 212 KB ans=NO N=9
8 Correct 1 ms 212 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 0 ms 340 KB ans=YES N=10
11 Correct 0 ms 340 KB ans=YES N=10
12 Correct 0 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 340 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 1 ms 340 KB ans=YES N=100
20 Correct 2 ms 468 KB ans=YES N=185
21 Correct 1 ms 340 KB ans=NO N=174
22 Correct 1 ms 596 KB ans=YES N=90
23 Correct 1 ms 340 KB ans=YES N=63
24 Correct 1 ms 340 KB ans=YES N=87
25 Correct 2 ms 468 KB ans=YES N=183
26 Correct 2 ms 468 KB ans=YES N=188
27 Correct 2 ms 468 KB ans=YES N=183
28 Correct 2 ms 468 KB ans=YES N=189
29 Correct 2 ms 468 KB ans=YES N=200
30 Correct 1 ms 468 KB ans=YES N=190
31 Correct 2 ms 468 KB ans=YES N=187
32 Correct 2 ms 596 KB ans=YES N=187
33 Correct 2 ms 596 KB ans=YES N=182
34 Correct 2 ms 724 KB ans=YES N=184
35 Correct 2 ms 852 KB ans=YES N=188
36 Correct 2 ms 724 KB ans=YES N=181
37 Correct 2 ms 724 KB ans=YES N=188
38 Correct 2 ms 1108 KB ans=YES N=191
39 Correct 1 ms 468 KB ans=YES N=196
40 Correct 1 ms 468 KB ans=YES N=196
41 Correct 1 ms 468 KB ans=YES N=196
42 Correct 1 ms 468 KB ans=YES N=196
43 Correct 3 ms 724 KB ans=YES N=195
44 Correct 1 ms 596 KB ans=NO N=1934
45 Correct 1 ms 340 KB ans=NO N=1965
46 Correct 106 ms 1040 KB ans=YES N=1824
47 Correct 125 ms 1108 KB ans=YES N=1981
48 Correct 99 ms 1032 KB ans=YES N=1814
49 Correct 119 ms 1304 KB ans=YES N=1854
50 Correct 114 ms 1024 KB ans=YES N=1831
51 Correct 126 ms 1108 KB ans=YES N=2000
52 Correct 115 ms 1292 KB ans=YES N=1847
53 Correct 99 ms 1396 KB ans=YES N=1819
54 Correct 101 ms 1060 KB ans=YES N=1986
55 Correct 146 ms 1924 KB ans=YES N=2000
56 Correct 123 ms 7380 KB ans=YES N=1834
57 Correct 114 ms 2772 KB ans=YES N=1860
58 Correct 104 ms 3540 KB ans=YES N=1898
59 Correct 117 ms 2148 KB ans=YES N=1832
60 Correct 119 ms 7104 KB ans=YES N=1929
61 Correct 150 ms 1620 KB ans=YES N=1919
62 Correct 106 ms 2772 KB ans=YES N=1882
63 Correct 90 ms 11772 KB ans=YES N=1922
64 Correct 107 ms 6556 KB ans=YES N=1989
65 Correct 62 ms 892 KB ans=YES N=1978
66 Correct 97 ms 11732 KB ans=YES N=1867
67 Correct 134 ms 1812 KB ans=YES N=1942
68 Correct 103 ms 9804 KB ans=NO N=66151
69 Correct 32 ms 4480 KB ans=NO N=64333
70 Execution timed out 3546 ms 12324 KB Time limit exceeded
71 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 129 ms 9736 KB ans=NO N=66151
2 Correct 35 ms 4100 KB ans=NO N=64333
3 Execution timed out 3567 ms 11932 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB ans=NO N=1934
2 Correct 2 ms 340 KB ans=NO N=1965
3 Correct 102 ms 1040 KB ans=YES N=1824
4 Incorrect 114 ms 1160 KB Contestant's solution is not lexicographically largest at index 1947 (1694 vs 1680)
5 Halted 0 ms 0 KB -