Submission #945819

#TimeUsernameProblemLanguageResultExecution timeMemory
945819vjudge1Building Skyscrapers (CEOI19_skyscrapers)C++17
54 / 100
301 ms54172 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

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

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, t; cin >> n >> t;
    map <int,map<int,int>> mp;
    set <ar<int,3>> st;
    for ( int i = 0; i < n; i++ ){
        int x, y; cin >> x >> y;
        if ( !i ) st.insert({x, y, i});
        else mp[x][y] = i;
    }
    vector <int> ans;
    while ( !st.empty() ){
        auto [u, v, j] = *st.begin();
        st.erase(st.begin());
        ans.pb(j);
        for ( int i = 0; i < 8; i++ ){
            int x = dx[i] + u, y = dy[i] + v;
            if ( mp[x][y] ){
                st.insert({x, y, mp[x][y]});
                mp[x][y] = 0;
            }
        }
    }
    if ( ans.size() != n ){
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    for ( auto &u: ans ){
        cout << u + 1 << ln;
    }

    cout << '\n';
}

Compilation message (stderr)

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:59:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   59 |     if ( ans.size() != n ){
      |          ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...