Submission #1096670

# Submission time Handle Problem Language Result Execution time Memory
1096670 2024-10-05T00:42:46 Z tuandq Park (BOI16_park) C++17
100 / 100
455 ms 71084 KB
#include <bits/stdc++.h>
using namespace std ;

typedef long long ll ;
typedef long double ld ;
typedef pair<int, int> pii ;
typedef pair<int, long long> pil ;
typedef pair<long long, int> pli ;
typedef pair<long long, long long> pll ;
typedef vector<int> vi ;
typedef vector<long long> vll ;

#define bitc(n) (__builtin_popcountll(n))
#define clz(n) (__builtin_clzll(n))
#define ctz(n) (__builtin_ctzll(n))
#define lg(n) (63 - __builtin_clzll(n))
#define MASK(k) (1ll << (k))
#define getbit(n, k) ((n) >> (k) & 1)
#define flipbit(n, k) ((n) ^ (1ll << (k)))
#define ton(n, k) ((n) | (1ll << (k)))
#define toff(n, k) ((n) & ~(1ll << (k)))

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define lwb lower_bound
#define upb upper_bound
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define taskname "input"

template<class X, class Y> bool maximize(X &x, const Y &y) {return (x < y ? x = y, true : false) ;}
template<class X, class Y> bool minimize(X &x, const Y &y) {return (x > y ? x = y, true : false) ;}

template<class X>
void remove_dup(vector<X> &ve) {
    sort(ve.begin(), ve.end()) ;
    ve.resize(unique(ve.begin(), ve.end()) - ve.begin()) ;
}

const ll mod = 1e9 + 7 ;
const ll INF = 1e18 ;
const int inf = 1e9 ;
const int N = 2e3 + 5 ;
const int M = 1e5 + 5 ;

/* Some Peach Tea Is Great ;-; */
/* Author : Tuandq */

pii b[M] ;
int n, m, w, h ;
pair<pii, int> a[N] ;

namespace sub3 {
    struct Disjoint {
        vector<int> lab ;
        int n ;

        Disjoint() {}
        Disjoint(int _n): n(_n) {
            lab.assign(n + 1, -1) ;
        }

        int find_set(int u) {
            return lab[u] < 0 ? u : (lab[u] = find_set(lab[u])) ;
        }
        
        bool join(int u, int v) {
            u = find_set(u) ;
            v = find_set(v) ;
            if(u != v) {
                if(lab[u] > lab[v]) swap(u, v) ;
                lab[u] += lab[v] ;
                lab[v] = u ;
                return true ;
            }
            return false ;
        }
    } dsu ;

    string res[M] ;

    ll sq(const int &x) {
        return 1ll * x * x ;
    }
    ld dis(pii u, pii v) {
        return 1.0 * sqrt(sq(v.fi - u.fi) + sq(v.se - u.se)) ;
    }

    void solve() {
        vector<pair<ld, pii>> edges ;
        for(int i = 1; i <= n; i ++) {
            edges.emplace_back(a[i].fi.fi - a[i].se, mp(i, n + 1)) ;
            edges.emplace_back(a[i].fi.se - a[i].se, mp(i, n + 2)) ;
            edges.emplace_back(w - a[i].fi.fi - a[i].se, mp(i, n + 3)) ;
            edges.emplace_back(h - a[i].fi.se - a[i].se, mp(i, n + 4)) ;
            for(int j = i + 1; j <= n; j ++) {
                edges.emplace_back(dis(a[i].fi, a[j].fi) - a[i].se - a[j].se, mp(i, j)) ;
            }
        }
        sort(all(edges)) ;

        vector<int> idx(m) ;
        iota(all(idx), 1) ;
        sort(all(idx), [](const int &i, const int &j) {
            return b[i].fi < b[j].fi ;
        }) ;

        dsu = Disjoint(n + 4) ;
        for(int i = 0, j = 0; i < m; i ++) {
            while(j < sz(edges) && edges[j].fi < 2.0 * b[idx[i]].fi) {
                dsu.join(edges[j].se.fi, edges[j].se.se) ;
                ++ j ;
            }

            int &e = b[idx[i]].se ; -- e ;

            vector<int> h(4) ;
            h[0] = dsu.find_set(n + 1) ;
            h[1] = dsu.find_set(n + 2) ;
            h[2] = dsu.find_set(n + 3) ;
            h[3] = dsu.find_set(n + 4) ;

            string &cur = res[idx[i]] = "" ;
            for(int k = 0; k < 4; k ++) {
                if(k == e) {
                    cur += (char)(k + '1') ;
                    continue ;
                }

                bool flag = false ;
                flag |= (h[0] == h[2] && getbit(e, 1) != getbit(k, 1)) ;
                flag |= (h[1] == h[3] && (getbit(e, 0) ^ getbit(e, 1) ^ getbit(k, 0) ^ getbit(k, 1))) ;
                flag |= (h[e] == h[(e + 1) & 3]) ;
                flag |= (h[k] == h[(k + 1) & 3]) ;
                
                if(!flag) {
                    cur += (char)(k + '1') ;
                }
            }
        }

        for(int i = 1; i <= m; i ++) {
            cout << res[i] << '\n' ;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin) ;
        freopen(taskname".out", "w", stdout) ;
    }

    cin >> n >> m >> w >> h ;
    for(int i = 1; i <= n; i ++) {
        int x, y, r ; cin >> x >> y >> r ;
        a[i] = mp(mp(x, y), r) ;
    }
    for(int i = 1; i <= m; i ++) {
        cin >> b[i].fi >> b[i].se ;
    }

    return sub3::solve(), 0 ;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:153:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  153 |         freopen(taskname".inp", "r", stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:154:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |         freopen(taskname".out", "w", stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 415 ms 69240 KB Output is correct
2 Correct 420 ms 69508 KB Output is correct
3 Correct 417 ms 69308 KB Output is correct
4 Correct 414 ms 69308 KB Output is correct
5 Correct 410 ms 69300 KB Output is correct
6 Correct 416 ms 69308 KB Output is correct
7 Correct 382 ms 69292 KB Output is correct
8 Correct 368 ms 69308 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6608 KB Output is correct
2 Correct 31 ms 6604 KB Output is correct
3 Correct 31 ms 6604 KB Output is correct
4 Correct 30 ms 6776 KB Output is correct
5 Correct 30 ms 6768 KB Output is correct
6 Correct 30 ms 6680 KB Output is correct
7 Correct 26 ms 6236 KB Output is correct
8 Correct 28 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 69240 KB Output is correct
2 Correct 420 ms 69508 KB Output is correct
3 Correct 417 ms 69308 KB Output is correct
4 Correct 414 ms 69308 KB Output is correct
5 Correct 410 ms 69300 KB Output is correct
6 Correct 416 ms 69308 KB Output is correct
7 Correct 382 ms 69292 KB Output is correct
8 Correct 368 ms 69308 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 31 ms 6608 KB Output is correct
12 Correct 31 ms 6604 KB Output is correct
13 Correct 31 ms 6604 KB Output is correct
14 Correct 30 ms 6776 KB Output is correct
15 Correct 30 ms 6768 KB Output is correct
16 Correct 30 ms 6680 KB Output is correct
17 Correct 26 ms 6236 KB Output is correct
18 Correct 28 ms 6224 KB Output is correct
19 Correct 439 ms 71072 KB Output is correct
20 Correct 455 ms 71084 KB Output is correct
21 Correct 451 ms 71036 KB Output is correct
22 Correct 449 ms 71068 KB Output is correct
23 Correct 442 ms 71068 KB Output is correct
24 Correct 425 ms 71076 KB Output is correct