Submission #564734

# Submission time Handle Problem Language Result Execution time Memory
564734 2022-05-19T14:23:07 Z MrDeboo Building Skyscrapers (CEOI19_skyscrapers) C++17
0 / 100
205 ms 30496 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,t;
    cin>>n>>t;
    pair<int,int>pr[n];
    for(auto &i:pr)cin>>i.first>>i.second;
    pair<int,int>por[n];
    for(int i=0;i<n;i++)por[i]=pr[i];
    sort(pr,pr+n);
    map<pair<int,int>,bool>vis;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
    int mn=1000000000000000000ll,k=0;
    pq.push(pr[k]);
    deque<pair<int,int>>g;
    int x[]={0,0,1,1,1};
    int y[]={-1,1,-1,0,1};
    int X[]={1,1,1,0,0,-1,-1,-1};
    int Y[]={-1,0,1,-1,1,1,-1,0};
    int cnt=0;
    while(pq.size()){
        pair<int,int>p=pq.top();
        pq.pop();
        // cout<<'f'<<p.first<<' '<<p.second<<endl;
        if(vis[p])continue;
        bool bl=0;
        for(int i=0;i<8;i++){
            pair<int,int>pp=make_pair(p.first+X[i],p.second+Y[i]);
            if(vis[pp])bl=1;
        }
        if(!bl)cnt++;
        assert(cnt<=1);
        vis[p]=1;
        g.push_back(p);
        for(int i=0;i<5;i++){
            pair<int,int>pp=make_pair(p.first+x[i],p.second+y[i]);
            int k=lower_bound(pr,pr+n,pp)-pr;
            if(k!=n&&pr[k]==pp&&!vis[pp]){
                // cout<<'g'<<pp.first<<' '<<pp.second<<endl;
                pq.push(pp);
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        if(vis[pr[i]])continue;
        bool bl=0;
        for(int w=0;w<8;w++){
            if(vis[{X[w]+pr[i].first,Y[w]+pr[i].second}])bl=1;
        }
        if(!bl)continue;
        pq.push(pr[i]);
        vis[pr[i]]=1;
        while(pq.size()){
            pair<int,int>p=pq.top();
            pq.pop();
            g.push_back(p);
            for(int w=0;w<5;w++){
                pair<int,int>pp={p.first+x[w],p.second+y[w]};
                if(!vis[pp]&&binary_search(pr,pr+n,pp)){
                    vis[pp]=1;
                    pq.push(pp);
                }
            }
        }
    }
    if(g.size()!=n){cout<<"NO";}
    else{
        cout<<"YES\n";
        map<pair<int,int>,int>mp;
        for(int i=0;i<n;i++){
            mp[g[i]]=i+1;
        }
        for(int i=0;i<n;i++)cout<<mp[por[i]]<<endl;
    }
}

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:73:16: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   73 |     if(g.size()!=n){cout<<"NO";}
      |        ~~~~~~~~^~~
skyscrapers.cpp:20:9: warning: unused variable 'mn' [-Wunused-variable]
   20 |     int mn=1000000000000000000ll,k=0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 0 ms 212 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 0 ms 212 KB ans=YES N=9
6 Incorrect 0 ms 212 KB Added cell 5 (0,0) not reachable from infinity
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 0 ms 212 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 0 ms 212 KB ans=YES N=9
6 Incorrect 0 ms 212 KB Added cell 5 (0,0) not reachable from infinity
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 0 ms 212 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 0 ms 212 KB ans=YES N=9
6 Incorrect 0 ms 212 KB Added cell 5 (0,0) not reachable from infinity
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1364 KB ans=NO N=1934
2 Correct 3 ms 724 KB ans=NO N=1965
3 Incorrect 5 ms 596 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB ans=YES N=1
2 Correct 0 ms 212 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 0 ms 212 KB ans=YES N=9
6 Incorrect 0 ms 212 KB Added cell 5 (0,0) not reachable from infinity
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 122 ms 10044 KB ans=NO N=66151
2 Correct 122 ms 30496 KB ans=NO N=64333
3 Incorrect 205 ms 12792 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1364 KB ans=NO N=1934
2 Correct 3 ms 724 KB ans=NO N=1965
3 Incorrect 5 ms 596 KB Full cells must be connected
4 Halted 0 ms 0 KB -