답안 #810999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810999 2023-08-06T19:22:55 Z treewave Building Skyscrapers (CEOI19_skyscrapers) C++17
0 / 100
151 ms 14040 KB
#include <bits/stdc++.h>

using namespace std;

int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, t; cin >> n >> t;
    vector<array<int, 2>> points;
    set<array<int, 3>> points_set;
    map<array<int, 2>, int> pt_to_idx;
    for (int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        points.push_back({x, y});
        points_set.insert({x, y, i});
        pt_to_idx[{x, y}] = i;
    }
    set<array<int, 2>> visited;
    vector<int> ans;
    array<int, 3> tp = *points_set.begin();
    visited.insert({tp[0], tp[1]});
    ans.push_back(tp[2]);
    points_set.erase(points_set.begin());
    set<array<int, 3>> poss;

    for (int d = 0; d < 8; d++){
        if (pt_to_idx.count({tp[0]+dx[d], tp[1]+dy[d]})){
            poss.insert({tp[0]+dx[d], tp[1]+dy[d], pt_to_idx[{tp[0]+dx[d], tp[1]+dy[d]}]});
            visited.insert({tp[0]+dx[d], tp[1]+dy[d]});
        }
    }

    while (!poss.empty()){
        tp = *poss.begin();
        poss.erase(poss.begin());
        ans.push_back(tp[2]);
        for (int d = 0; d < 8; d++){
            array<int, 2> new_pt = {tp[0] + dx[d], tp[1] + dy[d]};
            if (pt_to_idx.count(new_pt)){
                if (!visited.count(new_pt)){
                    visited.insert(new_pt);
                    poss.insert({new_pt[0], new_pt[1], pt_to_idx[new_pt]});
                }
            }
        }
    }
    if (ans.size() == n){
        reverse(ans.begin(), ans.end());
        cout << "YES\n";
        for (int i = 0; i < n; i++){
            cout << ans[i]+1 << "\n";
        }
    }
    else{
        cout << "NO\n";
    }
}

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:51:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     if (ans.size() == n){
      |         ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 0 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 0 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 0 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB ans=NO N=1934
2 Correct 1 ms 588 KB ans=NO N=1965
3 Incorrect 4 ms 596 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB ans=YES N=1
2 Correct 1 ms 212 KB ans=YES N=4
3 Correct 1 ms 212 KB ans=NO N=4
4 Incorrect 0 ms 212 KB Full cells must be connected
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 13248 KB ans=NO N=66151
2 Correct 47 ms 9384 KB ans=NO N=64333
3 Incorrect 151 ms 14040 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB ans=NO N=1934
2 Correct 1 ms 588 KB ans=NO N=1965
3 Incorrect 4 ms 596 KB Full cells must be connected
4 Halted 0 ms 0 KB -