Submission #253798

# Submission time Handle Problem Language Result Execution time Memory
253798 2020-07-28T17:22:38 Z Vimmer Drzava (COCI15_drzava) C++14
40 / 160
1000 ms 9340 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;
            }
    }

    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 = 1000000000000000;

    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 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 260 ms 2952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 330 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 96 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1087 ms 5632 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Execution timed out 1092 ms 9080 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1095 ms 8824 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1083 ms 9308 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1073 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1082 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 1094 ms 9336 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Execution timed out 1074 ms 9340 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -