Submission #253802

# Submission time Handle Problem Language Result Execution time Memory
253802 2020-07-28T17:24:17 Z Vimmer Drzava (COCI15_drzava) C++14
32 / 160
1000 ms 9336 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];

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.00000001)
                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);

        bool f[sz(vals) + 1][k];

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

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

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

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

                if (nval == 0) return 1;

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

                f[i + 1][vals[i]] = 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.0000001)
    {
        ld md = (r + l) * 0.5;

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

    cout << setprecision(3) << fixed;

    cout << l << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1080 ms 2936 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Execution timed out 1092 ms 2816 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 623 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1087 ms 2936 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1097 ms 2936 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 551 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1073 ms 5624 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1084 ms 9112 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1089 ms 9080 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1080 ms 8892 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1090 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1097 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1089 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Execution timed out 1093 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Execution timed out 1091 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1094 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1093 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1093 ms 9336 KB Time limit exceeded