# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
73202 | 2018-08-28T04:11:41 Z | test | Hill Reconstruction (FXCUP3_hill) | C++14 | 1341 ms | 46312 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MN = 300010; ll cross(pii a, pii b) { return 1LL * a.first * b.second - 1LL * a.second * b.first; } ll ccw(pii a, pii b, pii c) { pii p = pii(b.first - a.first, b.second - a.second); pii q = pii(c.first - a.first, c.second - a.second); return cross(p, q); } int gcd(int a, int b) { return b? gcd(b, a % b) : a; } int N; ll C; pii P[MN]; struct frac { int a, b; pii p; bool operator <(const frac &i) const { return 1LL * b * i.a < 1LL * a * i.b || (1LL * b * i.a == 1LL * a * i.b && p < i.p); } }; priority_queue<frac> pq; map<frac, int> chk; set<pii> pp; int main() { scanf("%d %lld", &N, &C); C *= 2; for(int i = 0; i < N; i++) { scanf("%d", &P[i].first); } for(int i = 0; i < N; i++) { scanf("%d", &P[i].second); } for(int i = 0; i < N - 1; i++) { pq.push({ P[i + 1].first - P[i].first, P[i + 1].second - P[i].second, P[i] }); } for(int i = 0; i < N; i++) { pp.insert(P[i]); } while(1) { while(!pq.empty() && chk[ pq.top() ]) pq.pop(); frac t = pq.top(); pii cur = t.p; pp.erase(cur); set<pii>::iterator it = pp.lower_bound(cur); if(it == pp.begin()) break; pii nxt = *it; pii pre = *(--it); ll need = abs(ccw(pre, cur, nxt)); if(need > C) break; C -= need; pq.pop(); chk[ { cur.first - pre.first, cur.second - pre.second, pre } ] = 1; pq.push({ nxt.first - pre.first, nxt.second - pre.second, pre }); } frac t = pq.top(); int A = t.a; int B = t.b; int G = gcd(A, B); A /= G; B /= G; printf("%d/%d", B, A); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 4 ms | 688 KB | Output is correct |
6 | Correct | 3 ms | 688 KB | Output is correct |
7 | Correct | 2 ms | 688 KB | Output is correct |
8 | Correct | 3 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 484 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 4 ms | 688 KB | Output is correct |
6 | Correct | 3 ms | 688 KB | Output is correct |
7 | Correct | 2 ms | 688 KB | Output is correct |
8 | Correct | 3 ms | 724 KB | Output is correct |
9 | Correct | 231 ms | 21804 KB | Output is correct |
10 | Correct | 266 ms | 21804 KB | Output is correct |
11 | Correct | 1341 ms | 46312 KB | Output is correct |
12 | Correct | 394 ms | 46312 KB | Output is correct |
13 | Correct | 140 ms | 46312 KB | Output is correct |
14 | Correct | 310 ms | 46312 KB | Output is correct |
15 | Correct | 440 ms | 46312 KB | Output is correct |
16 | Correct | 252 ms | 46312 KB | Output is correct |
17 | Correct | 404 ms | 46312 KB | Output is correct |
18 | Correct | 169 ms | 46312 KB | Output is correct |
19 | Correct | 220 ms | 46312 KB | Output is correct |