Submission #927336

#TimeUsernameProblemLanguageResultExecution timeMemory
927336DAleksaBulldozer (JOI17_bulldozer)C++17
25 / 100
652 ms1052 KiB
#include <bits/stdc++.h> using namespace std; struct point { int x; int y; int w; bool operator < (point p) { if(x == p.x) return y > p.y; return x < p.x; } }; struct frac { int p; int q; frac() { } frac(int _p, int _q) { p = _p; q = _q; } }; bool operator < (frac a, frac b) { return a.p * 1LL * b.q < b.p * 1LL * a.q; } const int N = 105; int n; point a[N]; map<frac, vector<pair<int, int>>> buc; vector<frac> slopes; int order[N], pos[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].w; for(int i = 1; i <= n; i++) { for(int j = i + 1; j <= n; j++) { int sign = 1; int dx = a[i].x - a[j].x, dy = a[i].y - a[j].y; if(dx < 0) sign *= -1; if(dy < 0) sign *= -1; dx = abs(dx); dy = abs(dy); int g = __gcd(dx, dy); dx /= g; dy /= g; if(dx != 0) dy *= sign; if(a[i] < a[j]) buc[frac(dy, dx)].emplace_back(i, j); else buc[frac(dy, dx)].emplace_back(j, i); slopes.push_back(frac(dy, dx)); } } sort(slopes.begin(), slopes.end(), [&](frac a, frac b) { return a.p * 1LL * b.q < b.p * 1LL * a.q; }); for(int i = 1; i <= n; i++) order[i] = i; sort(order + 1, order + n + 1, [&](int i, int j) { return a[i] < a[j]; }); for(int i = 1; i <= n; i++) pos[order[i]] = i; long long ans = 0; for(frac slope : slopes) { long long mx = 0; for(int i = 1; i <= n; i++) { mx = max((long long)a[order[i]].w, a[order[i]].w + mx); ans = max(ans, mx); } sort(buc[slope].begin(), buc[slope].end(), [&](pair<int, int> i, pair<int, int> j) { if(i.first == j.first) return a[i.second] < a[j.second]; return a[i.first] < a[j.first]; }); for(pair<int, int> p : buc[slope]) { int i = p.first, j = p.second; if(pos[i] < pos[j]) { swap(order[pos[i]], order[pos[j]]); swap(pos[i], pos[j]); } } } { long long mx = 0; for(int i = 1; i <= n; i++) { mx = max((long long)a[order[i]].w, a[order[i]].w + mx); ans = max(ans, mx); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...