답안 #598940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598940 2022-07-19T08:11:30 Z 박상훈(#8456) Building Skyscrapers (CEOI19_skyscrapers) C++17
0 / 100
3500 ms 12152 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];

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){
    if (x<0 || x>bx) return;
    if (y<0 || y>by) return;
    if (out[x][y]) return;
    out[x][y] = 1;
    if (b[x][y]) return;

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

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;
    fill(visited+1, visited+n+1, 0);
    dfs1(0, 0);
}

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[nnum] && 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++) 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] && out[a[i].x][a[i].y] && !cut[i]){
        ans.push_back(i);
        on[i] = 0;
        for (int k=0;k<8;k++){
            int nx = a[i].x + dx[k], ny = a[i].y + dy[k];
            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:122:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |     scanf("%d %d", &n, &typ);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
skyscrapers.cpp:125:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         scanf("%d %d", &a[i].x, &a[i].y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 340 KB ans=YES N=5
5 Correct 0 ms 340 KB ans=YES N=9
6 Correct 0 ms 340 KB ans=YES N=5
7 Correct 0 ms 212 KB ans=NO N=9
8 Correct 0 ms 212 KB ans=NO N=10
9 Incorrect 1 ms 340 KB Full cells must be connected
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 340 KB ans=YES N=5
5 Correct 0 ms 340 KB ans=YES N=9
6 Correct 0 ms 340 KB ans=YES N=5
7 Correct 0 ms 212 KB ans=NO N=9
8 Correct 0 ms 212 KB ans=NO N=10
9 Incorrect 1 ms 340 KB Full cells must be connected
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 340 KB ans=YES N=5
5 Correct 0 ms 340 KB ans=YES N=9
6 Correct 0 ms 340 KB ans=YES N=5
7 Correct 0 ms 212 KB ans=NO N=9
8 Correct 0 ms 212 KB ans=NO N=10
9 Incorrect 1 ms 340 KB Full cells must be connected
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB ans=NO N=1934
2 Correct 1 ms 452 KB ans=NO N=1965
3 Incorrect 72 ms 1096 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB ans=YES N=1
2 Correct 0 ms 340 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Correct 0 ms 340 KB ans=YES N=5
5 Correct 0 ms 340 KB ans=YES N=9
6 Correct 0 ms 340 KB ans=YES N=5
7 Correct 0 ms 212 KB ans=NO N=9
8 Correct 0 ms 212 KB ans=NO N=10
9 Incorrect 1 ms 340 KB Full cells must be connected
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 9988 KB ans=NO N=66151
2 Correct 30 ms 4412 KB ans=NO N=64333
3 Execution timed out 3556 ms 12152 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB ans=NO N=1934
2 Correct 1 ms 452 KB ans=NO N=1965
3 Incorrect 72 ms 1096 KB Full cells must be connected
4 Halted 0 ms 0 KB -