Submission #252824

# Submission time Handle Problem Language Result Execution time Memory
252824 2020-07-26T10:18:08 Z kartel Drzava (COCI15_drzava) C++14
64 / 160
351 ms 65540 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,nso-stack-protector,unroll-loops,fast-math,-O3")
//#define F first
//#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define Max_A int(1e9)
//#define el endl
#define pii pair <int, int>
#define err ld(1e-6)
#define Max_S int(3e6)
#define last(x) x.back()
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

ll ans = 1e18;
int x[N], y[N], k, n, i, cnt[N];
bool f[35];
vector <int> g[N];
bool mrk[N];

ll rast(int i, int j) {return (pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));}

void dfs(int v)
{
    if (mrk[v]) return;
    mrk[v] = 1;

    bool F[35]{0};
    for (int i = 0; i < k; i++) F[i] = f[i];
    for (int i = 0; i < k; i++)
    {
        if (F[i])
         f[(i + cnt[v]) % k] = 1;
    }

    f[cnt[v] % k] = 1;

    for (auto u : g[v])
    {
        if (mrk[u]) continue;

        dfs(u);
    }
}

bool gd(ll D)
{
    for (i = 1; i <= n; i++) g[i].clear(), mrk[i] = 0;

    for (i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        if (rast(i, j) <= D)
          g[i].pb(j), g[j].pb(i);

    for (i = 1; i <= n; i++)
    {
        if (mrk[i]) continue;

        for (int j = 0; j < k; j++) f[j] = 0;

        dfs(i);

        if (f[0]) return 1;
    }
    return 0;
}

int main()
{
    cout.precision(3);
    cout << fixed;
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n >> k;

    for (i = 1; i <= n; i++) cin >> x[i] >> y[i] >> cnt[i];

    ll l = 0;
    ll r = 2e18;
    while (l < r)
    {
        ll md = (l + r) / 2;

        if (gd(md))
             r = md;
        else l = md + 1;
    }

    cout << sqrt(ld(l));
}
# 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 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 290 ms 6400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 254 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 120 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 261 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 351 ms 6860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 81 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 155 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 201 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 223 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 175 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 262 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 206 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 200 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 212 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 180 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Runtime error 184 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Runtime error 187 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Runtime error 185 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)