Submission #112387

# Submission time Handle Problem Language Result Execution time Memory
112387 2019-05-19T10:08:33 Z Frankenween Drzava (COCI15_drzava) C++17
96 / 160
852 ms 5624 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define ull unsigned long long
#define pll pair<ll, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define ld long double
const ll mod1 = (ll)1e9 + 7;
const ll mod2 = (ll)1e9 + 9;
const ll BASE = 47;
const ll inf = (ll)1e18;
const long double e = 2.718281828459;
const long double pi = 3.141592653;
const ld EPS = 1e-9;


using namespace std;


template <class T>
istream& operator>>(istream &in, vector<T> &arr) {
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};


struct point {
    ll x, y, k;
};


ld dist(point a, point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}


vector<point> arr;
ll n, k;


bool can(vector<point> &have, ld d, point pt) {
    ll mask = 0;
    for (int i = 0; i < have.size(); i++) {
        if (dist(have[i], pt) <= d) {
            mask |= ((mask << have[i].k) | (1LL << have[i].k));
            mask |= (mask >> k);
            mask &= ((1 << k) - 1);
        }
    }
    return (mask & 1);
}


bool check(ld d) {
    ll l = 0, r = -1;
    multiset<pair<ll, ll>> kek;
    for (int i = 0; i < n; i++) {
        while (r + 1 < n and abs(arr[r + 1].x - arr[i].x) <= d) {
            kek.insert({arr[r + 1].y, r + 1});
            r++;
        }
        while (abs(arr[l].x - arr[i].x) > d) {
            kek.erase(kek.find({arr[l].y, l}));
            l++;
        }
        auto it = kek.lower_bound({ceil(arr[i].y - d), -inf});
        vector<point> have;
        while (it != kek.end() and it->first <= arr[i].y + d) {
            have.push_back(arr[it->second]);
            it++;
            if (have.size() >= 9 * k) {
                return true;
            }
        }
        if (can(have, d, arr[i])) {
            return true;
        }
    }
    return false;
}


void solve() {
    cin >> n >> k;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i].x >> arr[i].y >> arr[i].k;
        arr[i].k %= k;
    }
    sort(all(arr), [&](point a, point b) {
        return mp(a.x, a.y) < mp(b.x, b.y);
    });
    ld l = 0, r = 1e9;
    while (r - l > EPS) {
        ld mid = (l + r) / 2.0;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << fixed << setprecision(3) << r;
}


int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout.precision(30);
    ll seed = time(0);
    //cerr << "Seed: " << seed << "\n";
    srand(seed);
    solve();
    return 0;
}

Compilation message

drzava.cpp: In function 'bool can(std::vector<point>&, long double, point)':
drzava.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < have.size(); i++) {
                     ~~^~~~~~~~~~~~~
drzava.cpp: In function 'bool check(long double)':
drzava.cpp:79:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (have.size() >= 9 * k) {
                 ~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 420 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 7 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 8 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 193 ms 2856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 678 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 523 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 852 ms 5600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 559 ms 5528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 535 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 510 ms 5588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 520 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 514 ms 5568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -