Submission #1018571

# Submission time Handle Problem Language Result Execution time Memory
1018571 2024-07-10T06:58:49 Z caterpillow Drzava (COCI15_drzava) C++17
0 / 160
1 ms 604 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

template<template<typename> class Container, typename T>
ostream& operator<<(ostream& os, Container<T> o) {
    os << "{"; 
    int g = size(o); 
    for (auto i : o) os << i << ((--g) == 0 ? "" : ", "); 
    os << "}";
    return os;
}

void _print() {
    cerr << "\n";
}

template<typename T, typename ...V>
void _print(T t, V... v) {
    cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);
}

#ifdef LOCAL
#define dbg(x...) cerr << #x << " = "; _print(x);
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif

struct DSU {
    vt<int> e;
    void init(int n) { e.resize(n, -1); }
    int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (e[x] < e[y]) swap(x, y);
        e[y] += e[x];
        e[x] = y;
        return true;
    }
};

/*

bsearch on D
we can do a bitmask knapsack to check in O(fast)

idk how to build the connected components fast

*/

using db = long double;
using pd = pair<db, db>;
using t3 = tuple<db, int, int>;

int n, k;
vt<int> v;
vt<pd> pts;
vt<t3> edges;

#define sq(x) ((x) * (x))
db dist(pd a, pd b) {
    return sqrtl(sq(a.f - b.f) + sq(a.s - b.s));
}

void process() {
    cin >> n >> k;
    v.resize(n);
    pts.resize(n);
    F0R (i, n) {
        db x, y; ll pop;
        cin >> x >> y >> pop;
        pts[i] = {x, y};
        v[i] = pop % k;
    }

    vt<t3> poss;
    F0R (i, n) {
        FOR (j, i + 1, n) {
            poss.pb({dist(pts[i], pts[j]), i, j});
        }
    }
    sort(all(poss));
    DSU dsu; 
    dsu.init(n);
    for (auto [w, u, v] : poss) {
        if (dsu.unite(u, v)) {
            edges.pb({w, u, v});
        }
    }
}

void add_weight(ll& dp, ll w) {
    dp |= dp << w;
    dp |= dp >> k;
}

bool check(db d) {
    DSU dsu;
    dsu.init(n);
    for (auto [w, u, v] : edges) {
        if (w > d) break;
        dsu.unite(u, v);
    }
    vt<ll> msks(n, 1);
    F0R (u, n) {
        int rep = dsu.find(u);
        add_weight(msks[rep], v[u]);
    }
    F0R (i, n) {
        if (1 & (msks[i] >> k)) return true;
    }
    return false;
} 

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    process();

    const db eps = 1e-5;
    db lo = 0, hi = 2e8;
    while (hi - lo > eps) {
        db m = (lo + hi) / 2;
        if (check(m)) hi = m;
        else lo = m;
    }
    cout << setprecision(20) << hi << endl;
}

Compilation message

drzava.cpp:133:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  133 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -