Submission #96802

# Submission time Handle Problem Language Result Execution time Memory
96802 2019-02-12T04:07:37 Z Tieuphong Drzava (COCI15_drzava) C++11
160 / 160
430 ms 9684 KB
/***************************************************************************/
/**********************  LANG TU HAO HOA  **********************************/
/***************************************************************************/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define sz(x) ((int) x.size())
#define PB push_back
#define PF push_front
#define MP make_pair
#define ll long long
#define F first
#define S second
#define maxc 1000000007
#define MOD 1000000007
#define base 107
#define eps 1e-6
#define pi acos(-1)
#define N 50004
#define task ""
#define remain(x) ((x > MOD) ? (x - MOD) : x)

using namespace std;

void inline MIN(int &a, int b) {a = min(a, b);}

struct Point
{
    int x, y, k;

    bool operator < (const Point &B)
    {
        return x < B.x;
    }
} a[N];

int n, K, dp[N][33];

bool dd[N];

vector <int> ke[N];

void Enter()
{
    cin >> n >> K;
    FOR(i, 1, n)
    {
        cin >> a[i].x >> a[i].y >> a[i].k;
        a[i].k %= K;
    }
    sort(a+1, a+n+1);
}

double Dist(pii a, pii b)
{
    return (double)sqrt(1ll*(a.F-b.F)*(a.F-b.F) + 1ll*(a.S-b.S)*(a.S-b.S));
}

void DFS(int u, vector <int> &kVals)
{
    dd[u] = 1;
    kVals.PB(a[u].k);
    for (auto v : ke[u])
    {
        if (dd[v]) continue;
        DFS(v, kVals);
    }
}

bool Divisible(vector <int> &kVals)
{
    FOR(i, 0, sz(kVals)+1)
        FOR(k, 0, K) dp[i][k] = 0;
    dp[0][0] = 1;
    FOR(i, 0, sz(kVals))
        FOR(k, 0, K)
        {
            MIN(dp[i+1][k] += dp[i][k], 3);
            MIN(dp[i+1][(k+kVals[i])%K] += dp[i][k], 3);
        }
    return (dp[sz(kVals)][0] > 1);
}

bool CheckGraph()
{
    fill(dd+1, dd+n+1, 0);
    FOR(i, 1, n)
    {
        if (dd[i]) continue;
        vector <int> kVals;
        DFS(i, kVals);
        if (sz(kVals) >= K || Divisible(kVals)) return 1;
    }
    return 0;
}

bool Check(ll sqD)
{
    double D = (double)sqrt(sqD) + eps;
    set <pair <pii, int> > Built;
    for (int i = 1, j = 1; i <= n; ++i)
    {
        ke[i].clear();
        while (j < i && a[i].x - a[j].x > D)
        {
            Built.erase(MP(MP(a[j].y, a[j].x), j));
            j++;
        }
        if (!Built.empty())
        {
            for (auto it = Built.lower_bound(MP(MP(a[i].y - D, -1), -1)); it != Built.end() && it->F.F <= a[i].y + D; ++it)
            {
                double distance = Dist(it->F, MP(a[i].y, a[i].x));
                if (distance <= D)
                {
                    ke[i].PB(it->S);
                    ke[it->S].PB(i);
                }
                if (sz(ke[i]) >= K) return 1;
            }
        }
        Built.insert(MP(MP(a[i].y, a[i].x), i));
    }
    return CheckGraph();
}

void Produce()
{
    ll l = 0, r = 2e16+1;
    while (r - l > 1)
    {
        ll mid = (l + r) >> 1;
        if (Check(mid)) r = mid;
            else l = mid;
    }
    cout << fixed << setprecision(3) << sqrt(r);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen(task".inp", "r", stdin);
    //freopen(task".out", "w", stdout);
    Enter();
    Produce();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1524 KB Output is correct
2 Correct 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 12 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1528 KB Output is correct
2 Correct 7 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 8 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 7 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 6 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 7 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1532 KB Output is correct
2 Correct 78 ms 2164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1500 KB Output is correct
2 Correct 405 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 430 ms 9532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 311 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 357 ms 7164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1528 KB Output is correct
2 Correct 306 ms 7304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 258 ms 3704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 252 ms 4604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 248 ms 6132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 244 ms 6156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 237 ms 3984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
2 Correct 228 ms 4240 KB Output is correct