답안 #253810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253810 2020-07-28T17:28:24 Z Vimmer Drzava (COCI15_drzava) C++14
24 / 160
1000 ms 9388 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 50050
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 5> a5;

//typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int n, k, kol[N], pr[N];

ld x[N], y[N];

multiset <int> se[N];

bool f[5005][35];

void make(int x) {pr[x] = x; se[x].clear(); se[x].insert(kol[x]);}

int fnd(int x) {if (pr[x] != x) pr[x] = fnd(pr[x]); return pr[x];}

void link(int a, int b)
{
    if (sz(se[a]) < sz(se[b])) swap(a, b);

    pr[b] = a;

    for (auto it : se[b]) se[a].insert(it);
}

ld dist(int a, int b) {return sqrt(pow(x[a] - x[b], 2) + pow(y[a] - y[b], 2));}

bool can(ld x)
{
    for (int i = 0; i < n; i++) make(i);

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            int a = fnd(i), b = fnd(j);

            if (a == b) continue;

            if (x - dist(i, j) >= 0.0001)
                link(a, b);
        }

    set <int> st; st.clear();

    for (int i = 0; i < n; i++) st.insert(fnd(i));

    for (auto it : st)
    {
        vector <int> vals; vals.clear();

        for (auto itr : se[it]) vals.pb(itr);

        memset(f, 0, sizeof(f));

        f[1][vals[0]] = 1;

        if (vals[0] == 0) return 1;

        for (int i = 1; i < sz(vals); i++)
          for (int j = 0; j < k; j++)
            if (f[i][j] || j == 0)
            {
                f[i + 1][j] = 1;

                int nval = (j + vals[i]) % k;

                if (nval == 0) return 1;

                f[i + 1][nval] = 1;
            }
    }

    return 0;
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;

    for (int i = 0; i < n; i++) {cin >> x[i] >> y[i] >> kol[i]; kol[i] %= k;}

    ld l = 0, r = 100000000;

    while (r - l >= 0.0001)
    {
        ld md = (r + l) * 0.5;

        if (can(md)) r = md; else l = md;
    }

    cout << setprecision(3) << fixed;

    cout << l << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2944 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Execution timed out 1004 ms 3108 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2944 KB Output is correct
2 Execution timed out 1020 ms 3192 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 443 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2816 KB Output is correct
2 Execution timed out 1022 ms 3048 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Execution timed out 1087 ms 3064 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Correct 436 ms 3016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2944 KB Output is correct
2 Execution timed out 1071 ms 5632 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Execution timed out 1091 ms 9208 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2944 KB Output is correct
2 Execution timed out 1084 ms 9080 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2944 KB Output is correct
2 Execution timed out 1094 ms 8828 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2944 KB Output is correct
2 Execution timed out 1087 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2816 KB Output is correct
2 Execution timed out 1086 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2944 KB Output is correct
2 Execution timed out 1090 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2944 KB Output is correct
2 Execution timed out 1091 ms 9308 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Execution timed out 1088 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Execution timed out 1093 ms 9336 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2816 KB Output is correct
2 Execution timed out 1084 ms 9340 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2816 KB Output is correct
2 Execution timed out 1085 ms 9388 KB Time limit exceeded