# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
47822 |
2018-05-08T02:50:00 Z |
tieunhi |
Drzava (COCI15_drzava) |
C++14 |
|
1000 ms |
9848 KB |
#include <bits/stdc++.h>
#define PB push_back
#define N 70005
using namespace std;
using db = long double;
int n, k, dp[N][31], curTime, dd[N];
vector<int> g[N], component;
struct Point
{
int x, y, sz;
Point(int _x=0, int _y=0, int _sz=0) : x(_x), y(_y), sz(_sz) {}
friend bool operator < (const Point& a, const Point& b)
{
return a.x < b.x;
}
Point operator + (Point P) const
{
return {x + P.x, y + P.y, sz + P.sz};
}
Point operator - (Point P) const
{
return {x - P.x, y - P.y, sz - P.sz};
}
long long operator % (Point P) const
{
return 1ll*x*P.x + 1ll*y*P.y;
}
}a[N];
long long dist(Point u, Point v)
{
u = u - v;
return (u%u);
}
struct cmp
{
bool operator () (const int &p, const int &q)
{
if (a[p].y != a[q].y) return a[p].y < a[q].y;
return p < q;
}
};
set<int, cmp> s;
void DFS(int u)
{
dd[u] = curTime;
component.PB(a[u].sz);
for (auto v : g[u])
{
if (dd[v] == curTime) continue;
DFS(v);
}
}
bool exist()
{
int m = component.size();
if (m > k) return 1;
for (int i = 0; i <= m; i++)
for (int j = 0; j < k; j++) dp[i][j] = 0;
dp[0][0] = 1;
for (int i = 0; i < m; i++)
for (int j = 0; j < k; j++) {
dp[i+1][j] |= dp[i][j];
dp[i+1][(component[i] + j) % k] |= dp[i][j];
}
for (int i = 0; i < m; i++)
for (int j = 0; j < k; j++)
if ((j + component[i]) % k == 0 && dp[i][j])
return 1;
return 0;
}
bool check(long long D)
{
int d = sqrt(1.*D) + 1;
for (int i = 1; i <= n; i++)
g[i].clear();
s.clear();
int cur = 1;
for (int i = 1; i <= n; i++)
{
while (cur < i && a[i].x - a[cur].x > D)
s.erase(cur++);
if (s.empty())
{
s.insert(i);
continue;
}
a[0] = Point(a[i].x, a[i].y - d, 0);
int cnt = 0;
for (auto it = s.lower_bound(0); it != s.end(); it++)
{
int idx = *it;
if (a[idx].y - a[i].y > d) break;
if (++cnt >= 8*k)
return 1;
if (dist(a[idx], a[i]) <= D)
{
g[i].PB(idx);
g[idx].PB(i);
}
}
s.insert(i);
}
curTime++;
for (int i = 1; i <= n; i++)
if (dd[i] != curTime)
{
component.clear();
DFS(i);
if (exist())
return 1;
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y >> a[i].sz;
sort(a+1, a+n+1);
long long l = 0, r = 1e18;
while (r - l > 1)
{
long long mid = (r + l)/2;
if (check(mid)) r = mid;
else l = mid;
}
cout <<fixed<<setprecision(3)<<sqrt(1.*r);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
4 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2860 KB |
Output is correct |
2 |
Correct |
4 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2944 KB |
Output is correct |
2 |
Correct |
21 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
16 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3328 KB |
Output is correct |
2 |
Correct |
23 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3412 KB |
Output is correct |
2 |
Correct |
26 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3692 KB |
Output is correct |
2 |
Correct |
22 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3692 KB |
Output is correct |
2 |
Correct |
17 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3692 KB |
Output is correct |
2 |
Correct |
168 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3820 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
9848 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
9848 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
895 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9848 KB |
Output is correct |
2 |
Correct |
865 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Execution timed out |
1052 ms |
9848 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
449 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
552 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
482 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
469 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
520 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9848 KB |
Output is correct |
2 |
Correct |
430 ms |
9848 KB |
Output is correct |