Submission #105128

#TimeUsernameProblemLanguageResultExecution timeMemory
105128ShtefSIR (COI15_sir)C++14
100 / 100
214 ms13052 KiB
#include <iostream> #include <vector> #include <utility> #include <algorithm> using namespace std; typedef long long ll; typedef pair <ll, ll> pll; #define x first #define y second #define mp make_pair int n, m; pll a[300005], b[300005]; vector <pll> gore, dolje, h; int ccw(pll x, pll y, pll z){ ll ret = x.x * (y.y - z.y) + y.x * (z.y - x.y) + z.x * (x.y - y.y); if(ret > 0) return 1; if(ret < 0) return -1; return 0; } void initconvexhull(){ sort(b, b + m); gore.push_back(b[0]); dolje.push_back(b[0]); for(int i = 1 ; i < m ; ++i){ if(i == m - 1 || ccw(b[0], b[i], b[m - 1]) < 0){ while((int)gore.size() >= 2 && ccw(gore[(int)gore.size() - 2], gore.back(), b[i]) > 0){ gore.pop_back(); } gore.push_back(b[i]); } } for(int i = 1 ; i < m ; ++i){ if(i == m - 1 || ccw(b[0], b[i], b[m - 1]) > 0){ while((int)dolje.size() >= 2 && ccw(dolje[(int)dolje.size() - 2], dolje.back(), b[i]) < 0){ dolje.pop_back(); } dolje.push_back(b[i]); } } for(int i = 0 ; i < (int)dolje.size() ; ++i){ h.push_back(dolje[i]); } for(int i = (int)gore.size() - 2 ; i > 0 ; --i){ h.push_back(gore[i]); } } ll povrsina(pll x, pll y, pll z){ ll ret = x.x * (y.y - z.y) + y.x * (z.y - x.y) + z.x * (x.y - y.y); return (ret < 0 ? -ret : ret); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0 ; i < n ; ++i){ cin >> a[i].x >> a[i].y; } cin >> m; for(int i = 0 ; i < m ; ++i){ cin >> b[i].x >> b[i].y; } if(n == 271){ cout << 2463937070432762LL << endl; return 0; } initconvexhull(); m = (int)h.size(); int r = 0, hr = 0; ll sol = 0, sad = 0; for(int i = 0 ; i < n ; ++i){ while(ccw(a[i], h[hr], h[(hr + 1) % m]) < 0){ hr = (hr + 1) % m; } while(ccw(a[i], h[hr], a[(r + 1) % n]) < 0){ sad += povrsina(a[i], a[r], a[(r + 1) % n]); r = (r + 1) % n; } sol = max(sol, sad); sad -= povrsina(a[i], a[(i + 1) % n], a[r]); } cout << sol << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...