Submission #947938

#TimeUsernameProblemLanguageResultExecution timeMemory
947938ha819haBulldozer (JOI17_bulldozer)C++17
100 / 100
632 ms66532 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define x first #define y second #define all(v) (v).begin(), (v).end() const int sz = 1<<11; struct Seg { ll dat[sz*2], sf[sz*2], pf[sz*2], mx[sz*2]; void update(int x, ll v) { dat[x+=sz] = v; pf[x]=sf[x]=mx[x]=max(0LL, v); for(x/=2;x;x/=2) { pf[x] = max(pf[2*x], dat[2*x]+pf[2*x+1]); sf[x] = max(sf[2*x+1], dat[2*x+1]+sf[2*x]); mx[x] = max({mx[2*x],mx[2*x+1], sf[2*x]+pf[2*x+1]}); dat[x] = dat[2*x]+dat[2*x+1]; } } ll get() { return mx[1]; } } S; struct Point { ll x,y,v; bool operator < (const Point& rhs) const { return pll(x, y) < pll(rhs.x, rhs.y); } }; struct Line { ll dx,dy,i,j; bool operator < (const Line& rhs) const { ll l = dy*rhs.dx, r = dx*rhs.dy; return tie(l, i, j) < tie(r, rhs.i, rhs.j); } bool operator == (const Line& rhs) const { ll l = dy*rhs.dx, r = dx*rhs.dy; return l==r; } }; int main(void){ cin.tie(0)->sync_with_stdio(0); int n; cin>>n; vector<Point> p(n); for(auto& [x,y,v]:p) cin>>x>>y>>v; sort(all(p)); vector<int> pos(n); vector<Line> lines; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { ll dx = p[j].x-p[i].x; ll dy = p[j].y-p[i].y; if (dx < 0 || (dx == 0 && dy < 0))dx = -dx, dy = -dy; lines.push_back({dx,dy,i,j}); } } for(int i=0;i<n;i++) { S.update(i, p[i].v); pos[i]=i; } sort(all(lines)); ll ans = S.get(); for(int i=0;i<lines.size();i++) { int a = lines[i].i, b = lines[i].j; swap(pos[a], pos[b]); S.update(pos[a], p[a].v); S.update(pos[b], p[b].v); if(i+1<lines.size() && lines[i] == lines[i+1]) continue; ans = max(ans, S.get()); } cout<<ans; }

Compilation message (stderr)

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<lines.size();i++) {
      |                 ~^~~~~~~~~~~~~
bulldozer.cpp:88:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         if(i+1<lines.size() && lines[i] == lines[i+1]) continue;
      |            ~~~^~~~~~~~~~~~~
#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...