Submission #564499

# Submission time Handle Problem Language Result Execution time Memory
564499 2022-05-19T09:58:54 Z shrimb Building Skyscrapers (CEOI19_skyscrapers) C++17
8 / 100
682 ms 26096 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

int n, t;
int x[20], y[20];
int dx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dp[20][2000];
set<pair<int,int>> pts;
set<pair<int,int>> placed;
pair<int,int> best[20][2000];

bool BAD (int x, int y) {
    queue<array<int,3>> q; // {x, y, dis}
    q.push({x, y, 0});
    while (q.size()) {
        auto [a, b, c] = q.front();
        q.pop();
        if (placed.count({a, b})) continue;
        if (c >= 10) return 0;
        for (int d = 0 ; d < 4 ; d++) {
            int u = a + dx[d];
            int v = b + dy[d];
            q.push({u, v, c + 1});
        }
    }
    return 1;
}

bool rec (int i, int mask) {
    // cerr << i << " " << mask << endl;
    if (dp[i][mask] != -1) return dp[i][mask];
    if (BAD(x[i], y[i])) {
        return dp[i][mask] = 0;
    }
    if (mask) {
        bool good = 0;
        for (int d = 0 ; d < 8 ; d++) {
            int u = x[i] + dx[d];
            int v = y[i] + dy[d];
            if (placed.count({u, v})) good = 1;
        }
        if (!good) return dp[i][mask] = 0;
    }
    placed.insert({x[i], y[i]});
    mask += (1 << i); 
    if (__builtin_popcount(mask) == n) {
        return 1;
    }
    for (int j = 0 ; j < n ; j++) {
        if (!(mask & (1 << j))) {
            if (rec(j, mask)) {
                best[i][mask&~(1<<i)] = {j, mask};
                return dp[i][mask] = 1;
            }
        }
    }
    placed.erase({x[i], y[i]});
    return dp[i][mask] = 0;
}

void follow (int i, int mask) {
    // cerr << i << " " << mask << endl;
    cout << i + 1 << endl;
    if (__builtin_popcount(mask) == n - 1) return;
    follow(best[i][mask].first, best[i][mask].second);
}

signed main () {
    memset(dp, -1, sizeof dp);
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> t;

    for (int i = 0 ; i < n ; i++) {
        cin >> x[i] >> y[i];
        pts.insert({x[i], y[i]});
    }

    if (n > 1) {
        for (int i = 0 ; i < n ; i++) {
            bool good = 0;
            for (int d = 0 ; d < 8 ; d++) {
                int u = x[i] + dx[d];
                int v = y[i] + dy[d];
                if (pts.count({u, v})) good = 1;
            }
            if (!good) {
                cout << "NO\n";
                return 0;
            }
        }
    }

    cout << "YES\n";
    for (int i = 0 ; i < n ; i++) {
        if (rec(i, 0)) {
            follow(i, 0);
        }
    }
}

Compilation message

skyscrapers.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
skyscrapers.cpp: In function 'bool rec(long long int, long long int)':
skyscrapers.cpp:50:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   50 |         return dp[i][mask] = 0;
      |                ~~~~~~~~~~~~^~~
skyscrapers.cpp:59:39: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   59 |         if (!good) return dp[i][mask] = 0;
      |                           ~~~~~~~~~~~~^~~
skyscrapers.cpp:70:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   70 |                 return dp[i][mask] = 1;
      |                        ~~~~~~~~~~~~^~~
skyscrapers.cpp:75:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   75 |     return dp[i][mask] = 0;
      |            ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26076 KB ans=YES N=1
2 Correct 43 ms 26012 KB ans=YES N=4
3 Correct 0 ms 596 KB ans=NO N=4
4 Correct 58 ms 25980 KB ans=YES N=5
5 Correct 90 ms 25980 KB ans=YES N=9
6 Correct 48 ms 26056 KB ans=YES N=5
7 Correct 1 ms 596 KB ans=NO N=9
8 Correct 1 ms 596 KB ans=NO N=10
9 Correct 194 ms 26032 KB ans=YES N=10
10 Correct 682 ms 26028 KB ans=YES N=10
11 Correct 303 ms 25996 KB ans=YES N=10
12 Correct 198 ms 25976 KB ans=YES N=9
13 Correct 115 ms 25972 KB ans=YES N=9
14 Correct 119 ms 25980 KB ans=YES N=8
15 Correct 269 ms 26096 KB ans=YES N=8
16 Correct 1 ms 596 KB ans=NO N=2
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26076 KB ans=YES N=1
2 Correct 43 ms 26012 KB ans=YES N=4
3 Correct 0 ms 596 KB ans=NO N=4
4 Correct 58 ms 25980 KB ans=YES N=5
5 Correct 90 ms 25980 KB ans=YES N=9
6 Correct 48 ms 26056 KB ans=YES N=5
7 Correct 1 ms 596 KB ans=NO N=9
8 Correct 1 ms 596 KB ans=NO N=10
9 Correct 194 ms 26032 KB ans=YES N=10
10 Correct 682 ms 26028 KB ans=YES N=10
11 Correct 303 ms 25996 KB ans=YES N=10
12 Correct 198 ms 25976 KB ans=YES N=9
13 Correct 115 ms 25972 KB ans=YES N=9
14 Correct 119 ms 25980 KB ans=YES N=8
15 Correct 269 ms 26096 KB ans=YES N=8
16 Correct 1 ms 596 KB ans=NO N=2
17 Runtime error 182 ms 25980 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26076 KB ans=YES N=1
2 Correct 43 ms 26012 KB ans=YES N=4
3 Correct 0 ms 596 KB ans=NO N=4
4 Correct 58 ms 25980 KB ans=YES N=5
5 Correct 90 ms 25980 KB ans=YES N=9
6 Correct 48 ms 26056 KB ans=YES N=5
7 Correct 1 ms 596 KB ans=NO N=9
8 Correct 1 ms 596 KB ans=NO N=10
9 Correct 194 ms 26032 KB ans=YES N=10
10 Correct 682 ms 26028 KB ans=YES N=10
11 Correct 303 ms 25996 KB ans=YES N=10
12 Correct 198 ms 25976 KB ans=YES N=9
13 Correct 115 ms 25972 KB ans=YES N=9
14 Correct 119 ms 25980 KB ans=YES N=8
15 Correct 269 ms 26096 KB ans=YES N=8
16 Correct 1 ms 596 KB ans=NO N=2
17 Runtime error 182 ms 25980 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26076 KB ans=YES N=1
2 Correct 43 ms 26012 KB ans=YES N=4
3 Correct 0 ms 596 KB ans=NO N=4
4 Correct 58 ms 25980 KB ans=YES N=5
5 Correct 90 ms 25980 KB ans=YES N=9
6 Correct 48 ms 26056 KB ans=YES N=5
7 Correct 1 ms 596 KB ans=NO N=9
8 Correct 1 ms 596 KB ans=NO N=10
9 Correct 194 ms 26032 KB ans=YES N=10
10 Correct 682 ms 26028 KB ans=YES N=10
11 Correct 303 ms 25996 KB ans=YES N=10
12 Correct 198 ms 25976 KB ans=YES N=9
13 Correct 115 ms 25972 KB ans=YES N=9
14 Correct 119 ms 25980 KB ans=YES N=8
15 Correct 269 ms 26096 KB ans=YES N=8
16 Correct 1 ms 596 KB ans=NO N=2
17 Runtime error 182 ms 25980 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -