# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
47820 |
2018-05-08T02:22:34 Z |
tieunhi |
Drzava (COCI15_drzava) |
C++14 |
|
1000 ms |
63912 KB |
#include <bits/stdc++.h>
#define PB push_back
#define N 50005
#define eps 1e-5
using namespace std;
using db = double;
int n, k, dp[N][31], curTime, dd[N];
vector<int> g[N], component;
struct Point
{
db x, y;
int sz;
Point(db _x=0, db _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};
}
db operator % (Point P) const
{
return x*P.x + y*P.y;
}
}a[N];
db dist(Point u, Point v)
{
u = u - v;
return sqrt(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(u);
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][(a[component[i]].sz + j) % k] |= dp[i][j];
dp[i+1][j] |= dp[i][j];
}
for (int i = 0; i < m; i++)
for (int j = 0; j < k; j++)
if ((j + a[component[i]].sz) % k == 0 && dp[i][j])
return 1;
return 0;
}
bool check(db D)
{
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, a[i].sz %= k;
sort(a+1, a+n+1);
db l = 0, r = 1e9;
while (r - l > eps)
{
db mid = (r + l)/2;
if (check(mid)) r = mid;
else l = mid;
}
cout <<fixed<<setprecision(3)<<r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2868 KB |
Output is correct |
2 |
Correct |
4 ms |
2868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2868 KB |
Output is correct |
2 |
Correct |
19 ms |
3736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3736 KB |
Output is correct |
2 |
Correct |
12 ms |
3736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3736 KB |
Output is correct |
2 |
Correct |
18 ms |
3736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3736 KB |
Output is correct |
2 |
Correct |
19 ms |
3736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3736 KB |
Output is correct |
2 |
Correct |
20 ms |
3988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3988 KB |
Output is correct |
2 |
Correct |
14 ms |
3988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3988 KB |
Output is correct |
2 |
Correct |
180 ms |
8252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8252 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
56828 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
56828 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
57228 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
57228 KB |
Output is correct |
2 |
Correct |
682 ms |
57228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
57228 KB |
Output is correct |
2 |
Correct |
737 ms |
57228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
57228 KB |
Output is correct |
2 |
Execution timed out |
1042 ms |
63912 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
544 ms |
63912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
606 ms |
63912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
616 ms |
63912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
634 ms |
63912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
510 ms |
63912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
63912 KB |
Output is correct |
2 |
Correct |
527 ms |
63912 KB |
Output is correct |