Submission #1095949

# Submission time Handle Problem Language Result Execution time Memory
1095949 2024-10-03T12:50:25 Z yoav_s Building Skyscrapers (CEOI19_skyscrapers) C++17
22 / 100
3500 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, t;
    cin >> n >> t;
    vp cells(n);
    for (ll i=  0; i < n; i++) cin >> cells[i].f >> cells[i].s;
    v relevantX, relevantY;
    for (ll i = 0; i < n; i++)
    {
        relevantX.pb(cells[i].f - 1);
        relevantX.pb(cells[i].f);
        relevantX.pb(cells[i].f + 1);
        relevantY.pb(cells[i].s - 1);
        relevantY.pb(cells[i].s);
        relevantY.pb(cells[i].s + 1);
    }
    sort(all(relevantX)); sort(all(relevantY));
    relevantX.erase(unique(all(relevantX)), relevantX.end()); relevantY.erase(unique(all(relevantY)), relevantY.end());
    map<ll, ll> xShrink;
    map<ll, ll> yShrink;
    for (ll i = 0; i < relevantX.size(); i++) xShrink[relevantX[i]] = i + 1;
    for (ll i = 0; i < relevantY.size(); i++) yShrink[relevantY[i]] = i + 1;
    for (ll i = 0; i < n; i++) cells[i] = p(xShrink[cells[i].f], yShrink[cells[i].s]);
    ll maxX = relevantX.size() + 2, maxY = relevantY.size() + 2;
    vvvp supplyGraph(maxX, vvp(maxY));
    set<ll> available;
    for (ll i = 0; i < n; i++) available.insert(i);
    vvb occupied(maxX, vb(maxY, false));
    v order;
    vb possible(n, false);
    for (ll i = 0; i < n; i++)
    {
        bool done = false;
        for (ll x : available)
        {
            if (i != 0 && !possible[x]) continue;
            vvvp newSupplyGraph(maxX, vvp(maxY));
            occupied[cells[x].f][cells[x].s] = true;
            for (ll i = 0; i < maxX; i++)
            {
                for (ll j = 0; j < maxY; j++)
                {
                    if (occupied[i][j]) continue;
                    if (i + 1 < maxX && !occupied[i + 1][j])
                    {
                        newSupplyGraph[i][j].eb(i+1,j);
                        newSupplyGraph[i+1][j].eb(i,j);
                    }
                    if (j + 1 < maxY && !occupied[i][j + 1])
                    {
                        newSupplyGraph[i][j].eb(i,j+1);
                        newSupplyGraph[i][j+1].eb(i,j);
                    }
                }
            }
            vv component(maxX, v(maxY, -1));
            ll comp = 0;
            for (ll i = 0; i < maxX; i++)
            {
                for (ll j = 0; j < maxY; j++)
                {
                    if (component[i][j] != -1) continue;
                    stack<p> dfs;
                    dfs.emplace(i, j);
                    while (!dfs.empty())
                    {
                        auto top = dfs.top();
                        dfs.pop();
                        if (component[top.f][top.s] != -1) continue;
                        component[top.f][top.s] = comp;
                        for (auto x : newSupplyGraph[top.f][top.s]) dfs.push(x);
                    }
                    comp++;
                }
            }
            bool poss = true;
            for (ll y : available)
            {
                if (y != x && component[cells[y].f][cells[y].s] != component[maxX - 1][maxY - 1]) poss = false;
            }
            if (!poss)
            {
                occupied[cells[x].f][cells[x].s] = false;
                continue;
            }
            available.erase(x);
            order.pb(x);
            supplyGraph = newSupplyGraph;
            ll a = cells[x].f, b = cells[x].s;
            for (ll y : available)
            {
                if (abs(cells[y].f - a) <= 1 && abs(cells[y].s - b) <= 1)
                {
                    possible[y] = true;
                }
            }
            done = true;
            break;
        }
        if (!done)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    for (ll x : order) cout << x + 1 << "\n";
    return 0;
}

Compilation message

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:51:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (ll i = 0; i < relevantX.size(); i++) xShrink[relevantX[i]] = i + 1;
      |                    ~~^~~~~~~~~~~~~~~~~~
skyscrapers.cpp:52:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (ll i = 0; i < relevantY.size(); i++) yShrink[relevantY[i]] = i + 1;
      |                    ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB ans=YES N=1
2 Correct 1 ms 348 KB ans=YES N=4
3 Correct 0 ms 348 KB ans=NO N=4
4 Correct 1 ms 348 KB ans=YES N=5
5 Correct 0 ms 348 KB ans=YES N=9
6 Correct 0 ms 456 KB ans=YES N=5
7 Correct 0 ms 604 KB ans=NO N=9
8 Correct 1 ms 604 KB ans=NO N=10
9 Correct 0 ms 348 KB ans=YES N=10
10 Correct 0 ms 348 KB ans=YES N=10
11 Correct 0 ms 600 KB ans=YES N=10
12 Correct 0 ms 348 KB ans=YES N=9
13 Correct 0 ms 344 KB ans=YES N=9
14 Correct 0 ms 348 KB ans=YES N=8
15 Correct 0 ms 344 KB ans=YES N=8
16 Correct 0 ms 348 KB ans=NO N=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB ans=YES N=1
2 Correct 1 ms 348 KB ans=YES N=4
3 Correct 0 ms 348 KB ans=NO N=4
4 Correct 1 ms 348 KB ans=YES N=5
5 Correct 0 ms 348 KB ans=YES N=9
6 Correct 0 ms 456 KB ans=YES N=5
7 Correct 0 ms 604 KB ans=NO N=9
8 Correct 1 ms 604 KB ans=NO N=10
9 Correct 0 ms 348 KB ans=YES N=10
10 Correct 0 ms 348 KB ans=YES N=10
11 Correct 0 ms 600 KB ans=YES N=10
12 Correct 0 ms 348 KB ans=YES N=9
13 Correct 0 ms 344 KB ans=YES N=9
14 Correct 0 ms 348 KB ans=YES N=8
15 Correct 0 ms 344 KB ans=YES N=8
16 Correct 0 ms 348 KB ans=NO N=2
17 Correct 1 ms 348 KB ans=YES N=17
18 Correct 1 ms 344 KB ans=YES N=25
19 Correct 5 ms 348 KB ans=YES N=100
20 Correct 18 ms 580 KB ans=YES N=185
21 Correct 3 ms 1540 KB ans=NO N=174
22 Correct 4 ms 348 KB ans=YES N=90
23 Correct 3 ms 344 KB ans=YES N=63
24 Correct 4 ms 600 KB ans=YES N=87
25 Correct 35 ms 344 KB ans=YES N=183
26 Correct 47 ms 604 KB ans=YES N=188
27 Correct 38 ms 600 KB ans=YES N=183
28 Correct 37 ms 604 KB ans=YES N=189
29 Correct 58 ms 604 KB ans=YES N=200
30 Correct 22 ms 600 KB ans=YES N=190
31 Correct 39 ms 608 KB ans=YES N=187
32 Correct 26 ms 604 KB ans=YES N=187
33 Correct 22 ms 820 KB ans=YES N=182
34 Correct 38 ms 860 KB ans=YES N=184
35 Correct 63 ms 1112 KB ans=YES N=188
36 Correct 28 ms 604 KB ans=YES N=181
37 Correct 33 ms 856 KB ans=YES N=188
38 Correct 78 ms 1372 KB ans=YES N=191
39 Correct 13 ms 628 KB ans=YES N=196
40 Correct 13 ms 604 KB ans=YES N=196
41 Correct 14 ms 604 KB ans=YES N=196
42 Correct 16 ms 600 KB ans=YES N=196
43 Correct 46 ms 860 KB ans=YES N=195
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB ans=YES N=1
2 Correct 1 ms 348 KB ans=YES N=4
3 Correct 0 ms 348 KB ans=NO N=4
4 Correct 1 ms 348 KB ans=YES N=5
5 Correct 0 ms 348 KB ans=YES N=9
6 Correct 0 ms 456 KB ans=YES N=5
7 Correct 0 ms 604 KB ans=NO N=9
8 Correct 1 ms 604 KB ans=NO N=10
9 Correct 0 ms 348 KB ans=YES N=10
10 Correct 0 ms 348 KB ans=YES N=10
11 Correct 0 ms 600 KB ans=YES N=10
12 Correct 0 ms 348 KB ans=YES N=9
13 Correct 0 ms 344 KB ans=YES N=9
14 Correct 0 ms 348 KB ans=YES N=8
15 Correct 0 ms 344 KB ans=YES N=8
16 Correct 0 ms 348 KB ans=NO N=2
17 Correct 1 ms 348 KB ans=YES N=17
18 Correct 1 ms 344 KB ans=YES N=25
19 Correct 5 ms 348 KB ans=YES N=100
20 Correct 18 ms 580 KB ans=YES N=185
21 Correct 3 ms 1540 KB ans=NO N=174
22 Correct 4 ms 348 KB ans=YES N=90
23 Correct 3 ms 344 KB ans=YES N=63
24 Correct 4 ms 600 KB ans=YES N=87
25 Correct 35 ms 344 KB ans=YES N=183
26 Correct 47 ms 604 KB ans=YES N=188
27 Correct 38 ms 600 KB ans=YES N=183
28 Correct 37 ms 604 KB ans=YES N=189
29 Correct 58 ms 604 KB ans=YES N=200
30 Correct 22 ms 600 KB ans=YES N=190
31 Correct 39 ms 608 KB ans=YES N=187
32 Correct 26 ms 604 KB ans=YES N=187
33 Correct 22 ms 820 KB ans=YES N=182
34 Correct 38 ms 860 KB ans=YES N=184
35 Correct 63 ms 1112 KB ans=YES N=188
36 Correct 28 ms 604 KB ans=YES N=181
37 Correct 33 ms 856 KB ans=YES N=188
38 Correct 78 ms 1372 KB ans=YES N=191
39 Correct 13 ms 628 KB ans=YES N=196
40 Correct 13 ms 604 KB ans=YES N=196
41 Correct 14 ms 604 KB ans=YES N=196
42 Correct 16 ms 600 KB ans=YES N=196
43 Correct 46 ms 860 KB ans=YES N=195
44 Runtime error 393 ms 1048576 KB Execution killed with signal 9
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 409 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB ans=YES N=1
2 Correct 1 ms 348 KB ans=YES N=4
3 Correct 0 ms 348 KB ans=NO N=4
4 Correct 1 ms 348 KB ans=YES N=5
5 Correct 0 ms 348 KB ans=YES N=9
6 Correct 0 ms 456 KB ans=YES N=5
7 Correct 0 ms 604 KB ans=NO N=9
8 Correct 1 ms 604 KB ans=NO N=10
9 Correct 0 ms 348 KB ans=YES N=10
10 Correct 0 ms 348 KB ans=YES N=10
11 Correct 0 ms 600 KB ans=YES N=10
12 Correct 0 ms 348 KB ans=YES N=9
13 Correct 0 ms 344 KB ans=YES N=9
14 Correct 0 ms 348 KB ans=YES N=8
15 Correct 0 ms 344 KB ans=YES N=8
16 Correct 0 ms 348 KB ans=NO N=2
17 Correct 1 ms 348 KB ans=YES N=17
18 Correct 1 ms 344 KB ans=YES N=25
19 Correct 5 ms 348 KB ans=YES N=100
20 Correct 18 ms 580 KB ans=YES N=185
21 Correct 3 ms 1540 KB ans=NO N=174
22 Correct 4 ms 348 KB ans=YES N=90
23 Correct 3 ms 344 KB ans=YES N=63
24 Correct 4 ms 600 KB ans=YES N=87
25 Correct 35 ms 344 KB ans=YES N=183
26 Correct 47 ms 604 KB ans=YES N=188
27 Correct 38 ms 600 KB ans=YES N=183
28 Correct 37 ms 604 KB ans=YES N=189
29 Correct 58 ms 604 KB ans=YES N=200
30 Correct 22 ms 600 KB ans=YES N=190
31 Correct 39 ms 608 KB ans=YES N=187
32 Correct 26 ms 604 KB ans=YES N=187
33 Correct 22 ms 820 KB ans=YES N=182
34 Correct 38 ms 860 KB ans=YES N=184
35 Correct 63 ms 1112 KB ans=YES N=188
36 Correct 28 ms 604 KB ans=YES N=181
37 Correct 33 ms 856 KB ans=YES N=188
38 Correct 78 ms 1372 KB ans=YES N=191
39 Correct 13 ms 628 KB ans=YES N=196
40 Correct 13 ms 604 KB ans=YES N=196
41 Correct 14 ms 604 KB ans=YES N=196
42 Correct 16 ms 600 KB ans=YES N=196
43 Correct 46 ms 860 KB ans=YES N=195
44 Runtime error 393 ms 1048576 KB Execution killed with signal 9
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3525 ms 33968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 409 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -