# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72317 | 2018-08-26T07:02:06 Z | 마릴린 희정(#2180, gs14004, ho94949) | Hill Reconstruction (FXCUP3_hill) | C++17 | 537 ms | 7196 KB |
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; const int MAXN = 300050; int n; lint c; pi den, a[MAXN]; vector<pi> stk; lint ccw(pi a, pi b, pi c){ int dx1 = b.first - a.first; int dy1 = b.second - a.second; int dx2 = c.first - a.first; int dy2 = c.second - a.second; return 1ll * dx1 * dy2 - 1ll * dy1 * dx2; } bool big_giulgi(pi a, pi b, llf c){ return (b.second - a.second) > (b.first - a.first) * c; } lint trial(llf x){ stk.clear(); stk.push_back(a[0]); lint ans = 0; for(int i=1; i<n; i++){ while(stk.size() >= 2 && big_giulgi(stk.back(), a[i], x)){ ans += ccw(stk[stk.size()-2], stk.back(), a[i]); stk.pop_back(); } if(big_giulgi(stk.back(), a[i], x)){ return 3e18; } stk.push_back(a[i]); } return ans; } bool cmp(pi a, pi b){ return 1ll * a.first * b.second < 1ll * b.first * a.second; } int gcd(int x, int y){ return y ? gcd(y, x%y) : x; } int main(){ scanf("%d %lld",&n,&c); c <<= 1; for(int i=0; i<n; i++) scanf("%d",&a[i].first); for(int i=0; i<n; i++) scanf("%d",&a[i].second); long double s = 0, e = 2e9; for(int i=0; i<100; i++){ long double m = (s+e)/2; if(trial(m) <= c) e = m; else s = m; } assert(trial(e) <= c); pi ans(0, 1); for(int i=1; i<stk.size(); i++){ ans = max(ans, pi(stk[i].second - stk[i-1].second, stk[i].first - stk[i-1].first), cmp); } int g = gcd(ans.first, ans.second); ans.first /= g; ans.second /= g; printf("%d/%d\n", ans.first, ans.second); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 432 KB | Output is correct |
4 | Correct | 3 ms | 432 KB | Output is correct |
5 | Correct | 5 ms | 468 KB | Output is correct |
6 | Correct | 3 ms | 468 KB | Output is correct |
7 | Correct | 3 ms | 596 KB | Output is correct |
8 | Correct | 4 ms | 596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 432 KB | Output is correct |
4 | Correct | 3 ms | 432 KB | Output is correct |
5 | Correct | 5 ms | 468 KB | Output is correct |
6 | Correct | 3 ms | 468 KB | Output is correct |
7 | Correct | 3 ms | 596 KB | Output is correct |
8 | Correct | 4 ms | 596 KB | Output is correct |
9 | Correct | 337 ms | 7040 KB | Output is correct |
10 | Correct | 307 ms | 7040 KB | Output is correct |
11 | Correct | 537 ms | 7104 KB | Output is correct |
12 | Correct | 483 ms | 7152 KB | Output is correct |
13 | Correct | 214 ms | 7152 KB | Output is correct |
14 | Correct | 159 ms | 7152 KB | Output is correct |
15 | Correct | 498 ms | 7156 KB | Output is correct |
16 | Correct | 326 ms | 7196 KB | Output is correct |
17 | Correct | 415 ms | 7196 KB | Output is correct |
18 | Correct | 209 ms | 7196 KB | Output is correct |
19 | Correct | 229 ms | 7196 KB | Output is correct |