# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20644 |
2017-02-13T06:38:45 Z |
model_code |
None (KOI16_dist) |
C++11 |
|
436 ms |
4584 KB |
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX = 100005;
ll sq(ll x) { return x*x; }
const pii operator + (const pii &l, const pii &r) { return pii(l.first + r.first, l.second + r.second); }
const pii operator - (const pii &l, const pii &r) { return pii(l.first - r.first, l.second - r.second); }
const pii operator * (const int t, const pii &r) { return pii(t * r.first, t * r.second); }
const ll operator ^ (const pii &l, const pii &r) { return (ll)l.first * r.second - (ll)r.first * l.second; }
ll size(pii c) { return sq(c.first) + sq(c.second); }
bool comp(const pii &l, const pii &r) {
if (r == pii(0, 0)) return false;
if (l == pii(0, 0)) return true;
if ((l^r) != 0) return (l^r) > 0;
else return size(l) < size(r);
}
void convex_hull(const vector<pii> &P, vector<pii> &res)
{
vector<pii> T;
pii mn = P[0];
for (int i = 0; i < P.size(); i++) if (mn > P[i]) mn = P[i];
for (int i = 0; i < P.size(); i++) T.push_back(P[i] - mn);
sort(T.begin(), T.end(), comp);
for (int i = 0; i < T.size(); i++) {
pii c = T[i];
while (res.size() >= 2) {
pii p0 = res.back(), p1 = res[res.size() - 2];
if (((p1 - p0) ^ (c - p0)) >= 0) res.pop_back();
else break;
}
if (!res.size() || res.back() != c) res.push_back(c);
}
for (int i = 0; i < res.size(); i++) res[i] = res[i] + mn;
}
ll furthest_length(const vector<pii> &P)
{
vector<pii> C;
convex_hull(P, C);
C.push_back(C[0]);
ll dist = 0, cur = 1;
for (; cur + 1 < C.size(); cur++) {
ll ccw = (C[0] - C[1]) ^ (C[cur] - C[cur + 1]);
if (ccw <= 0) break;
}
dist = size(C[cur] - C[0]);
for (int i = 1; i + 1 < C.size(); i++) {
for (; cur + 1 < C.size(); cur++) {
ll ccw = (C[i] - C[i + 1]) ^ (C[cur] - C[cur + 1]);
dist = max(size(C[cur] - C[i]), dist);
if (ccw <= 0) break;
}
dist = max(size(C[cur] - C[i]), dist);
}
return dist;
}
ll furthest_length(int N, ll t, pii D[MX], pii V[MX])
{
vector<pii> T(N);
for (int i = 0; i < N; i++) T[i] = D[i] + t * V[i];
return furthest_length(T);
}
int main()
{
static int N, T;
static pii D[MX], V[MX];
scanf("%d%d", &N, &T);
for (int i = 0; i < N; i++) {
scanf("%d%d%d%d", &D[i].first, &D[i].second, &V[i].first, &V[i].second);
}
ll l = 0, r = T, m1, m2;
while (l <= r) {
m1 = (l * 2 + r) / 3;
m2 = (l + r * 2 + 1) / 3;
ll d1 = furthest_length(N, m1, D, V);
ll d2 = furthest_length(N, m2, D, V);
if (d1 <= d2) r = m2 - 1;
else l = m1 + 1;
}
swap(l, r);
printf("%lld\n%lld\n", r, furthest_length(N, r, D, V));
return 0;
}
Compilation message
dist.cpp: In function 'void convex_hull(const std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
dist.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < P.size(); i++) if (mn > P[i]) mn = P[i];
^
dist.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < P.size(); i++) T.push_back(P[i] - mn);
^
dist.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < T.size(); i++) {
^
dist.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < res.size(); i++) res[i] = res[i] + mn;
^
dist.cpp: In function 'll furthest_length(const std::vector<std::pair<int, int> >&)':
dist.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; cur + 1 < C.size(); cur++) {
^
dist.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i + 1 < C.size(); i++) {
^
dist.cpp:59:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; cur + 1 < C.size(); cur++) {
^
dist.cpp: In function 'int main()':
dist.cpp:81:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &T);
^
dist.cpp:83:72: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &D[i].first, &D[i].second, &V[i].first, &V[i].second);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3496 KB |
Output is correct |
2 |
Correct |
0 ms |
3496 KB |
Output is correct |
3 |
Correct |
0 ms |
3496 KB |
Output is correct |
4 |
Correct |
0 ms |
3496 KB |
Output is correct |
5 |
Correct |
0 ms |
3496 KB |
Output is correct |
6 |
Correct |
0 ms |
3496 KB |
Output is correct |
7 |
Correct |
0 ms |
3496 KB |
Output is correct |
8 |
Correct |
0 ms |
3496 KB |
Output is correct |
9 |
Correct |
0 ms |
3496 KB |
Output is correct |
10 |
Correct |
0 ms |
3496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3496 KB |
Output is correct |
2 |
Correct |
0 ms |
3496 KB |
Output is correct |
3 |
Correct |
0 ms |
3496 KB |
Output is correct |
4 |
Correct |
0 ms |
3496 KB |
Output is correct |
5 |
Correct |
0 ms |
3496 KB |
Output is correct |
6 |
Correct |
0 ms |
3496 KB |
Output is correct |
7 |
Correct |
0 ms |
3496 KB |
Output is correct |
8 |
Correct |
0 ms |
3496 KB |
Output is correct |
9 |
Correct |
0 ms |
3496 KB |
Output is correct |
10 |
Correct |
0 ms |
3496 KB |
Output is correct |
11 |
Correct |
9 ms |
3496 KB |
Output is correct |
12 |
Correct |
9 ms |
3496 KB |
Output is correct |
13 |
Correct |
6 ms |
3496 KB |
Output is correct |
14 |
Correct |
9 ms |
3496 KB |
Output is correct |
15 |
Correct |
9 ms |
3496 KB |
Output is correct |
16 |
Correct |
3 ms |
3496 KB |
Output is correct |
17 |
Correct |
6 ms |
3496 KB |
Output is correct |
18 |
Correct |
3 ms |
3496 KB |
Output is correct |
19 |
Correct |
6 ms |
3496 KB |
Output is correct |
20 |
Correct |
6 ms |
3496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
4320 KB |
Output is correct |
2 |
Correct |
89 ms |
4320 KB |
Output is correct |
3 |
Correct |
89 ms |
4320 KB |
Output is correct |
4 |
Correct |
76 ms |
4580 KB |
Output is correct |
5 |
Correct |
93 ms |
4320 KB |
Output is correct |
6 |
Correct |
53 ms |
4584 KB |
Output is correct |
7 |
Correct |
63 ms |
4320 KB |
Output is correct |
8 |
Correct |
46 ms |
4320 KB |
Output is correct |
9 |
Correct |
86 ms |
4576 KB |
Output is correct |
10 |
Correct |
93 ms |
4320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3496 KB |
Output is correct |
2 |
Correct |
0 ms |
3496 KB |
Output is correct |
3 |
Correct |
0 ms |
3496 KB |
Output is correct |
4 |
Correct |
0 ms |
3496 KB |
Output is correct |
5 |
Correct |
0 ms |
3496 KB |
Output is correct |
6 |
Correct |
0 ms |
3496 KB |
Output is correct |
7 |
Correct |
0 ms |
3496 KB |
Output is correct |
8 |
Correct |
0 ms |
3496 KB |
Output is correct |
9 |
Correct |
0 ms |
3496 KB |
Output is correct |
10 |
Correct |
0 ms |
3496 KB |
Output is correct |
11 |
Correct |
9 ms |
3496 KB |
Output is correct |
12 |
Correct |
9 ms |
3496 KB |
Output is correct |
13 |
Correct |
6 ms |
3496 KB |
Output is correct |
14 |
Correct |
9 ms |
3496 KB |
Output is correct |
15 |
Correct |
9 ms |
3496 KB |
Output is correct |
16 |
Correct |
3 ms |
3496 KB |
Output is correct |
17 |
Correct |
6 ms |
3496 KB |
Output is correct |
18 |
Correct |
3 ms |
3496 KB |
Output is correct |
19 |
Correct |
6 ms |
3496 KB |
Output is correct |
20 |
Correct |
6 ms |
3496 KB |
Output is correct |
21 |
Correct |
89 ms |
4320 KB |
Output is correct |
22 |
Correct |
89 ms |
4320 KB |
Output is correct |
23 |
Correct |
89 ms |
4320 KB |
Output is correct |
24 |
Correct |
76 ms |
4580 KB |
Output is correct |
25 |
Correct |
93 ms |
4320 KB |
Output is correct |
26 |
Correct |
53 ms |
4584 KB |
Output is correct |
27 |
Correct |
63 ms |
4320 KB |
Output is correct |
28 |
Correct |
46 ms |
4320 KB |
Output is correct |
29 |
Correct |
86 ms |
4576 KB |
Output is correct |
30 |
Correct |
93 ms |
4320 KB |
Output is correct |
31 |
Correct |
416 ms |
4320 KB |
Output is correct |
32 |
Correct |
423 ms |
4320 KB |
Output is correct |
33 |
Correct |
436 ms |
4320 KB |
Output is correct |
34 |
Correct |
416 ms |
4320 KB |
Output is correct |
35 |
Correct |
433 ms |
4320 KB |
Output is correct |
36 |
Correct |
423 ms |
4576 KB |
Output is correct |
37 |
Correct |
373 ms |
4320 KB |
Output is correct |
38 |
Correct |
256 ms |
4320 KB |
Output is correct |
39 |
Correct |
309 ms |
4320 KB |
Output is correct |
40 |
Correct |
436 ms |
4320 KB |
Output is correct |
41 |
Correct |
423 ms |
4580 KB |
Output is correct |
42 |
Correct |
426 ms |
4576 KB |
Output is correct |