# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
252778 |
2020-07-26T08:58:06 Z |
islingr |
Drzava (COCI15_drzava) |
C++14 |
|
331 ms |
5124 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define f first
#define s second
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int N = 1 << 16, K = 1 << 6;
const ll inf = 2e8;
short k;
int n, cur;
vector<int> cmp[N];
bool dp[K][K];
int nxt[N], rnk[N];
int head(int u) { return nxt[u] < 0 ? u : nxt[u] = head(nxt[u]); }
void unite(int u, int v) {
u = head(u); v = head(v);
if (u == v) return;
if (rnk[u] > rnk[v]) nxt[v] = u;
else {
nxt[u] = v;
if (rnk[u] == rnk[v]) ++rnk[v];
}
}
using pii = pair<int, int>;
pair<pii, short> tmp[N];
pii p(int i) { return tmp[i].f; }
short v(int i) { return tmp[i].s; }
ll norm(const pii &p, const pii &q) {
return 1ll * (p.f - q.f) * (p.f - q.f) + 1ll * (p.s - q.s) * (p.s - q.s);
}
bool f(ll d) {
ld r = sqrt(ld(d));
set<pair<int, int>> S;
int l = 0;
rep(u, 0, n) nxt[u] = rnk[u] = -1, cmp[u].clear();
rep(i, 0, n) {
if (p(i).f - p(l).f > r)
S.erase({p(l).s, l}), ++l;
int cnt = 0;
for (auto it = S.lb({ceil(p(i).s - r), -1});
it != end(S) && it->f - r <= p(i).s; ++it, ++cnt) {
if (norm(p(it->s), p(i)) <= d)
unite(it->s, i);
if (cnt > k) return true;
}
S.insert({p(i).s, i});
}
rep(u, 0, n) cmp[head(u)].eb(u);
rep(z, 0, n) {
auto &a = cmp[z]; int n = sz(a);
if (a.empty()) continue;
if (sz(a) > k) return true;
rep(i, 0, n) rep(w, 0, k) dp[i][w] = 0;
dp[0][v(a[0])] = 1;
rep(i, 1, n) {
dp[i][v(a[i])] = 1;
rep(w, 0, k)
if (dp[i - 1][w])
dp[i][(w + v(a[i])) % k] = dp[i][w] = true;
if (dp[i][0]) return true;
}
}
return false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
rep(i, 0, n) {
int x, y, c; cin >> x >> y >> c;
tmp[i] = {{x, y}, c % k};
}
sort(tmp, tmp + n);
ll l = 0, r = inf * inf;
while (r - l > 1) {
ll m = l + (r - l + 1) / 2;
if (f(m)) r = m;
else l = m;
}
cout << fixed << setprecision(3) << sqrt(ld(r));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
1 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
2 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
95 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
325 ms |
5088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
331 ms |
5124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
275 ms |
4804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
296 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
319 ms |
5088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
221 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
264 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
247 ms |
4644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
234 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1920 KB |
Output is correct |
2 |
Correct |
271 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
244 ms |
4600 KB |
Output is correct |