Submission #799542

# Submission time Handle Problem Language Result Execution time Memory
799542 2023-07-31T15:48:17 Z Ronin13 Building Skyscrapers (CEOI19_skyscrapers) C++17
8 / 100
1235 ms 51540 KB
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <bitset>

#define ll long long 
#define ull unsigned ll
#define f first
#define s second 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define mp make_pair

using namespace std;

const ll mod = 998244353;
const int nmax = 400001;
bool marked[nmax];
set <int> st[nmax];
int cnt[nmax];
set <int> good;
vector <vector <int> > vv(nmax);
bool out[nmax];
vector <int> p(nmax);
map <pii, int> m;
bool used[nmax];
int x[nmax], y[nmax];
vector <pii> d;
int n;

void dfs(int x, int y){
    used[m[mp(x, y)]] = true;
    for(int i = 0; i < d.size(); i++){
        int nx = x + d[i].f, ny = y + d[i].s;
        if(!m[mp(nx, ny)]) continue;
        if(used[m[mp(nx, ny)]]) continue;
        dfs(nx, ny);
    }
}

bool A[nmax], B[nmax];
int cur;

void make_set(int v){
    p[v] = v;
   // out[v] = true;
 //   sz[v] = 1;
}


int find_set(int v){
    return p[v] == v ? v : p[v] = find_set(p[v]);
}
void rem(int ind){
    good.erase(ind);
    B[ind] = false;
}

void add(int ind){
    if(cnt[ind] == st[ind].size() && cnt[ind]) B[ind] = true;
}



void recount_regions(int ind){
    int lst = 0;
    cnt[ind] = 0;
    A[ind] = false;
    B[ind] = false;
    good.erase(ind);
    for(int i = 0; i < d.size(); i++){
        int nx = x[ind] + d[i].f, ny = y[ind] + d[i].s;
        if(m[mp(nx, ny)] > n) {
            lst = 1;
           if(d[i].f && d[i].s) continue;
            A[ind] |= out[find_set(m[mp(nx, ny)])];
        }
        else{ if(lst == 1) cnt[ind]++; lst =0;}
    }
    if(!cnt[ind] && lst) cnt[ind]++;
    
    if(cnt[ind] == st[ind].size() && !st[ind].empty()) B[ind] = true;
    if(A[ind] && B[ind]) good.insert(ind);
}

void union_sets(int a, int b){
    a = find_set(a);
     b= find_set(b);
     if(a == b) return;
     if(vv[a].size() < vv[b].size()) swap(a, b);
     p[b] = a;
    out[a] |= out[b];
    for(int i = 0; i < vv[b].size(); i++){
        int x = vv[b][i];
        if(marked[x]) continue;
        rem(x);
        st[x].erase(b);
        st[x].insert(a);
        add(x);
        recount_regions(x);
        vv[a].pb(x);
    }
    
}

void make_empty(int ind){
    marked[m[mp(x[ind], y[ind])]] = true;
    m[mp(x[ind], y[ind])] = cur++;
    make_set(cur - 1);
    for(int i = 0; i < d.size(); i++){
        int nx = d[i].f + x[ind], ny = d[i].s + y[ind];
        pii o = mp(nx, ny);
        if(m[o] > 0 && m[o] <= n) rem(m[o]), st[m[o]].insert(cur - 1), vv[cur - 1].pb(m[o]), add(m[o]);
    }
    for(int i = 0; i < d.size(); i++){
        int nx = d[i].f + x[ind], ny = d[i].s + y[ind];
        if(d[i].f && d[i].s) continue;
        if(m[mp(nx, ny)] > n) union_sets(cur - 1, m[mp(nx, ny)]);
    }
    for(int i = 0; i < d.size(); i++){
        int nx = d[i].f + x[ind], ny = d[i].s + y[ind];
        pii o = mp(nx, ny);
        if(m[o] > 0 && m[o] <= n) recount_regions(m[o]);
    }
}

int main(){
    d.pb(mp(-1, -1)); d.pb(mp(-1, 0)); d.pb(mp(-1, 1)); 
    d.pb(mp(0, 1)); d.pb(mp(1, 1)); d.pb(mp(1, 0)); d.pb(mp(1, -1));
    d.pb(mp(0, -1)); d.pb(mp(-1, -1));
    cin >> n;
    int t; cin >> t;
    cur = n + 1;
    int mxx, mxy;
    mxy= mxx = -1e9 - 10;
    int mnx, mny;
    mnx = mny = 1e9 + 10;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i];
        mxx = max(mxx, x[i]);
        mnx = min(mnx, x[i]);
        mxy = max(mxy, y[i]);
        mny = min(mny, y[i]);
        m[mp(x[i], y[i])] = i;
    }
    dfs(x[1], y[1]);
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            cout << "NO\n";
            return 0;
        }
    }
    vector <pii> empt;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < d.size(); j++){
            int nx = x[i] + d[j].f, ny = y[i] + d[j].s;
            if(!m[mp(nx, ny)] ){
                make_set(cur);
                if(nx < mnx || ny < mny || nx > mxx || ny > mxy)
                    out[cur] = true;
                empt.pb(mp(nx, ny));
                m[mp(nx, ny)] = cur++;
            }
            if(j != d.size() - 1)
           if(m[mp(nx, ny)] > n) st[i].insert(m[mp(nx, ny)]),
            vv[m[mp(nx, ny)]].pb(i);
        }
    }
    for(int i = 1; i <= n; i++)
        recount_regions(i);
    
    for(int i = 0; i <empt.size(); ++i){
        int x = empt[i].f, y = empt[i].s;
        for(int j = 0; j < d.size(); j++){
            int nx = x + d[j].f, ny = y + d[j].s;
            if(d[j].f != 0 && d[j].s != 0) continue;
            if(m[mp(nx, ny)] > n){
                union_sets(m[empt[i]], m[mp(nx, ny)]);
            }
        }
    }
    
    vector <int> ans;
    while(!good.empty()){
        ans.pb(*good.rbegin());
        good.erase(ans.back());
        make_empty(ans.back());
    }
    
    cout << "YES\n";
    reverse(ans.begin(), ans.end());
    for(int i =0 ; i < ans.size(); i++){
        cout << ans[i] << "\n";
    }   
    return 0;
}

Compilation message

skyscrapers.cpp: In function 'void dfs(int, int)':
skyscrapers.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i = 0; i < d.size(); i++){
      |                    ~~^~~~~~~~~~
skyscrapers.cpp: In function 'void add(int)':
skyscrapers.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     if(cnt[ind] == st[ind].size() && cnt[ind]) B[ind] = true;
      |        ~~~~~~~~~^~~~~~~~~~~~~~~~~
skyscrapers.cpp: In function 'void recount_regions(int)':
skyscrapers.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i = 0; i < d.size(); i++){
      |                    ~~^~~~~~~~~~
skyscrapers.cpp:88:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     if(cnt[ind] == st[ind].size() && !st[ind].empty()) B[ind] = true;
      |        ~~~~~~~~~^~~~~~~~~~~~~~~~~
skyscrapers.cpp: In function 'void union_sets(int, int)':
skyscrapers.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for(int i = 0; i < vv[b].size(); i++){
      |                    ~~^~~~~~~~~~~~~~
skyscrapers.cpp: In function 'void make_empty(int)':
skyscrapers.cpp:116:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |     for(int i = 0; i < d.size(); i++){
      |                    ~~^~~~~~~~~~
skyscrapers.cpp:121:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for(int i = 0; i < d.size(); i++){
      |                    ~~^~~~~~~~~~
skyscrapers.cpp:126:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |     for(int i = 0; i < d.size(); i++){
      |                    ~~^~~~~~~~~~
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:161:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |         for(int j = 0; j < d.size(); j++){
      |                        ~~^~~~~~~~~~
skyscrapers.cpp:170:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  170 |             if(j != d.size() - 1)
      |                ~~^~~~~~~~~~~~~~~
skyscrapers.cpp:178:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  178 |     for(int i = 0; i <empt.size(); ++i){
      |                    ~~^~~~~~~~~~~~
skyscrapers.cpp:180:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |         for(int j = 0; j < d.size(); j++){
      |                        ~~^~~~~~~~~~
skyscrapers.cpp:198:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  198 |     for(int i =0 ; i < ans.size(); i++){
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30036 KB ans=YES N=1
2 Correct 14 ms 30104 KB ans=YES N=4
3 Correct 14 ms 30036 KB ans=NO N=4
4 Correct 14 ms 30116 KB ans=YES N=5
5 Correct 14 ms 29992 KB ans=YES N=9
6 Correct 13 ms 30036 KB ans=YES N=5
7 Correct 13 ms 30036 KB ans=NO N=9
8 Correct 13 ms 30036 KB ans=NO N=10
9 Correct 13 ms 30036 KB ans=YES N=10
10 Correct 13 ms 30036 KB ans=YES N=10
11 Correct 13 ms 30036 KB ans=YES N=10
12 Correct 14 ms 30036 KB ans=YES N=9
13 Correct 14 ms 30020 KB ans=YES N=9
14 Correct 14 ms 30108 KB ans=YES N=8
15 Correct 14 ms 30036 KB ans=YES N=8
16 Correct 14 ms 30076 KB ans=NO N=2
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30036 KB ans=YES N=1
2 Correct 14 ms 30104 KB ans=YES N=4
3 Correct 14 ms 30036 KB ans=NO N=4
4 Correct 14 ms 30116 KB ans=YES N=5
5 Correct 14 ms 29992 KB ans=YES N=9
6 Correct 13 ms 30036 KB ans=YES N=5
7 Correct 13 ms 30036 KB ans=NO N=9
8 Correct 13 ms 30036 KB ans=NO N=10
9 Correct 13 ms 30036 KB ans=YES N=10
10 Correct 13 ms 30036 KB ans=YES N=10
11 Correct 13 ms 30036 KB ans=YES N=10
12 Correct 14 ms 30036 KB ans=YES N=9
13 Correct 14 ms 30020 KB ans=YES N=9
14 Correct 14 ms 30108 KB ans=YES N=8
15 Correct 14 ms 30036 KB ans=YES N=8
16 Correct 14 ms 30076 KB ans=NO N=2
17 Correct 13 ms 30036 KB ans=YES N=17
18 Correct 13 ms 30036 KB ans=YES N=25
19 Correct 14 ms 30036 KB ans=YES N=100
20 Correct 15 ms 30164 KB ans=YES N=185
21 Correct 14 ms 30092 KB ans=NO N=174
22 Correct 15 ms 30124 KB ans=YES N=90
23 Correct 14 ms 30072 KB ans=YES N=63
24 Correct 15 ms 30084 KB ans=YES N=87
25 Correct 15 ms 30084 KB ans=YES N=183
26 Correct 16 ms 30096 KB ans=YES N=188
27 Correct 16 ms 30164 KB ans=YES N=183
28 Correct 17 ms 30164 KB ans=YES N=189
29 Correct 16 ms 30140 KB ans=YES N=200
30 Correct 17 ms 30168 KB ans=YES N=190
31 Correct 16 ms 30096 KB ans=YES N=187
32 Incorrect 17 ms 30200 KB Full cells must be connected
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30036 KB ans=YES N=1
2 Correct 14 ms 30104 KB ans=YES N=4
3 Correct 14 ms 30036 KB ans=NO N=4
4 Correct 14 ms 30116 KB ans=YES N=5
5 Correct 14 ms 29992 KB ans=YES N=9
6 Correct 13 ms 30036 KB ans=YES N=5
7 Correct 13 ms 30036 KB ans=NO N=9
8 Correct 13 ms 30036 KB ans=NO N=10
9 Correct 13 ms 30036 KB ans=YES N=10
10 Correct 13 ms 30036 KB ans=YES N=10
11 Correct 13 ms 30036 KB ans=YES N=10
12 Correct 14 ms 30036 KB ans=YES N=9
13 Correct 14 ms 30020 KB ans=YES N=9
14 Correct 14 ms 30108 KB ans=YES N=8
15 Correct 14 ms 30036 KB ans=YES N=8
16 Correct 14 ms 30076 KB ans=NO N=2
17 Correct 13 ms 30036 KB ans=YES N=17
18 Correct 13 ms 30036 KB ans=YES N=25
19 Correct 14 ms 30036 KB ans=YES N=100
20 Correct 15 ms 30164 KB ans=YES N=185
21 Correct 14 ms 30092 KB ans=NO N=174
22 Correct 15 ms 30124 KB ans=YES N=90
23 Correct 14 ms 30072 KB ans=YES N=63
24 Correct 15 ms 30084 KB ans=YES N=87
25 Correct 15 ms 30084 KB ans=YES N=183
26 Correct 16 ms 30096 KB ans=YES N=188
27 Correct 16 ms 30164 KB ans=YES N=183
28 Correct 17 ms 30164 KB ans=YES N=189
29 Correct 16 ms 30140 KB ans=YES N=200
30 Correct 17 ms 30168 KB ans=YES N=190
31 Correct 16 ms 30096 KB ans=YES N=187
32 Incorrect 17 ms 30200 KB Full cells must be connected
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 30164 KB ans=NO N=1934
2 Correct 14 ms 30152 KB ans=NO N=1965
3 Incorrect 37 ms 30676 KB Contestant's solution is not lexicographically largest at index 1810 (1669 vs 1650)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30036 KB ans=YES N=1
2 Correct 14 ms 30104 KB ans=YES N=4
3 Correct 14 ms 30036 KB ans=NO N=4
4 Correct 14 ms 30116 KB ans=YES N=5
5 Correct 14 ms 29992 KB ans=YES N=9
6 Correct 13 ms 30036 KB ans=YES N=5
7 Correct 13 ms 30036 KB ans=NO N=9
8 Correct 13 ms 30036 KB ans=NO N=10
9 Correct 13 ms 30036 KB ans=YES N=10
10 Correct 13 ms 30036 KB ans=YES N=10
11 Correct 13 ms 30036 KB ans=YES N=10
12 Correct 14 ms 30036 KB ans=YES N=9
13 Correct 14 ms 30020 KB ans=YES N=9
14 Correct 14 ms 30108 KB ans=YES N=8
15 Correct 14 ms 30036 KB ans=YES N=8
16 Correct 14 ms 30076 KB ans=NO N=2
17 Correct 13 ms 30036 KB ans=YES N=17
18 Correct 13 ms 30036 KB ans=YES N=25
19 Correct 14 ms 30036 KB ans=YES N=100
20 Correct 15 ms 30164 KB ans=YES N=185
21 Correct 14 ms 30092 KB ans=NO N=174
22 Correct 15 ms 30124 KB ans=YES N=90
23 Correct 14 ms 30072 KB ans=YES N=63
24 Correct 15 ms 30084 KB ans=YES N=87
25 Correct 15 ms 30084 KB ans=YES N=183
26 Correct 16 ms 30096 KB ans=YES N=188
27 Correct 16 ms 30164 KB ans=YES N=183
28 Correct 17 ms 30164 KB ans=YES N=189
29 Correct 16 ms 30140 KB ans=YES N=200
30 Correct 17 ms 30168 KB ans=YES N=190
31 Correct 16 ms 30096 KB ans=YES N=187
32 Incorrect 17 ms 30200 KB Full cells must be connected
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 135 ms 42972 KB ans=NO N=66151
2 Correct 53 ms 34508 KB ans=NO N=64333
3 Incorrect 1235 ms 51540 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 30164 KB ans=NO N=1934
2 Correct 14 ms 30152 KB ans=NO N=1965
3 Incorrect 37 ms 30676 KB Contestant's solution is not lexicographically largest at index 1810 (1669 vs 1650)
4 Halted 0 ms 0 KB -