답안 #96801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96801 2019-02-12T03:55:41 Z Tieuphong Drzava (COCI15_drzava) C++11
32 / 160
1000 ms 16872 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)
{
    memset(dp, 0, sizeof (dp));
    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;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 8056 KB Output is correct
2 Correct 56 ms 7928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 8024 KB Output is correct
2 Correct 90 ms 8020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 8056 KB Output is correct
2 Execution timed out 1085 ms 8056 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 8028 KB Output is correct
2 Execution timed out 1074 ms 8056 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 7928 KB Output is correct
2 Correct 837 ms 8056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 8056 KB Output is correct
2 Correct 572 ms 8176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 7928 KB Output is correct
2 Execution timed out 1022 ms 8184 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 7928 KB Output is correct
2 Execution timed out 1066 ms 8056 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 7928 KB Output is correct
2 Execution timed out 1068 ms 9208 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 8028 KB Output is correct
2 Execution timed out 1087 ms 16872 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 8020 KB Output is correct
2 Execution timed out 1069 ms 16672 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 8024 KB Output is correct
2 Execution timed out 1060 ms 14156 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 314 ms 8056 KB Output is correct
2 Execution timed out 1082 ms 14480 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 8056 KB Output is correct
2 Execution timed out 1067 ms 14504 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 7928 KB Output is correct
2 Execution timed out 1080 ms 10924 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 7928 KB Output is correct
2 Execution timed out 1076 ms 11824 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 8056 KB Output is correct
2 Execution timed out 1081 ms 13324 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 8056 KB Output is correct
2 Execution timed out 1085 ms 13364 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 8056 KB Output is correct
2 Execution timed out 1076 ms 11256 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 8056 KB Output is correct
2 Execution timed out 1079 ms 11512 KB Time limit exceeded