Submission #564643

# Submission time Handle Problem Language Result Execution time Memory
564643 2022-05-19T12:27:36 Z 1zaid1 Building Skyscrapers (CEOI19_skyscrapers) C++14
0 / 100
116 ms 57828 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 2e6 + 5, MOD = 1e9+7;
struct point {int x, y, i;};
vector<int> node[M];
int vis[M], cnt;

vector<int> ans;
void dfs(int s) {
    vis[s] = true;
    ans.push_back(s);
    cnt++;
    int mx = 0, tmp = 0;
    for (int i:node[s]) mx += vis[i];
    if (mx >= 2) {
        swap(ans[ans.size()-1], ans[ans.size()-2]);
        tmp = ans.back();
        ans.pop_back();
    }

    for (int i:node[s]) {
        if (!vis[i]) dfs(i);
    }

    if (tmp) ans.push_back(tmp);
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    srand(time(0));
    
    int n, t;
    cin >> n >> t;

    vector<point> v(n);
    for (auto&i:v) cin >> i.x >> i.y;
    int ind = 1; for (auto&i:v) i.i = ind++;

    vector<point> p;
    sort(v.begin(), v.end(), [](point a, point b){if (a.y == b.y) return a.x < b.x; return a.y < b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || v[i].y == v[i-1].y)) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if (a.x == b.x) return a.y < b.y; return a.x < b.x;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || v[i].x == v[i-1].x)) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].y+1 == p[j].y) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if ((a.x+a.y) == (b.x+b.y)) return a.x < b.x; return a.x+a.y < b.x+b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || (v[i].x+v[i].y) == (v[i-1].x+v[i-1].y))) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }
 
    p.clear();
    sort(v.begin(), v.end(), [](point a, point b){if ((a.x-a.y) == (b.x-b.y)) return a.x < b.x; return a.x-a.y < b.x-b.y;});
    for (int i = 0; i < n; i++) {
        while (i < n && (!i || (v[i].x-v[i].y) == (v[i-1].x-v[i-1].y))) {
            p.push_back(v[i++]);
        }
 
        for (int j = 1; j < p.size(); j++) {
            if (p[j-1].x+1 == p[j].x) {
                node[p[j].i].push_back(p[j-1].i);
                node[p[j-1].i].push_back(p[j].i);
            }
        }
 
        p.clear();
        p.push_back(v[i]);
    }

    dfs(1);
    if (cnt >= n) {
        cout << "YES" << endl;
        for (int i:ans) cout << i << endl;
    } else cout << "NO" << endl;

    return 0;
}

/*
3 2
0 0
0 1
0 2
*/

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:49:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:67:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:85:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
skyscrapers.cpp:103:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for (int j = 1; j < p.size(); j++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47176 KB ans=YES N=1
2 Correct 24 ms 47184 KB ans=YES N=4
3 Correct 22 ms 47216 KB ans=NO N=4
4 Correct 27 ms 47184 KB ans=YES N=5
5 Incorrect 25 ms 47252 KB Full cells must be connected
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47176 KB ans=YES N=1
2 Correct 24 ms 47184 KB ans=YES N=4
3 Correct 22 ms 47216 KB ans=NO N=4
4 Correct 27 ms 47184 KB ans=YES N=5
5 Incorrect 25 ms 47252 KB Full cells must be connected
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47176 KB ans=YES N=1
2 Correct 24 ms 47184 KB ans=YES N=4
3 Correct 22 ms 47216 KB ans=NO N=4
4 Correct 27 ms 47184 KB ans=YES N=5
5 Incorrect 25 ms 47252 KB Full cells must be connected
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB ans=NO N=1934
2 Correct 24 ms 47456 KB ans=NO N=1965
3 Incorrect 25 ms 47600 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47176 KB ans=YES N=1
2 Correct 24 ms 47184 KB ans=YES N=4
3 Correct 22 ms 47216 KB ans=NO N=4
4 Correct 27 ms 47184 KB ans=YES N=5
5 Incorrect 25 ms 47252 KB Full cells must be connected
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 57512 KB ans=NO N=66151
2 Correct 58 ms 49536 KB ans=NO N=64333
3 Incorrect 116 ms 57828 KB Full cells must be connected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB ans=NO N=1934
2 Correct 24 ms 47456 KB ans=NO N=1965
3 Incorrect 25 ms 47600 KB Full cells must be connected
4 Halted 0 ms 0 KB -