제출 #219519

#제출 시각아이디문제언어결과실행 시간메모리
219519balbitBulldozer (JOI17_bulldozer)C++14
80 / 100
968 ms33872 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define SZ(x) (int)(x.size()) #define ALL(x) x.begin(),x.end() #define pb push_back #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S &&...y) {cerr<<x<<", "; _do(y...);} #define IOS() #else #define IOS() ios::sync_with_stdio(0), cin.tie(0) #define bug(...) #define endl '\n' #endif // BALBIT #define assert(...) const int maxn = 2005; struct seg{ ll sum, lv, rv, v; seg *lc=0, *rc=0; }; int n; void pull(seg *&o) { if (!o->lc) { if (o->v > 0) o->sum = o->lv = o->rv = o->v; else { o->sum = o->v; o->lv = o->rv = o->v = 0; } }else{ assert(o->lc && o->rc); o->sum = o->lc->sum + o->rc->sum; o->lv = max(o->lc->lv, o->lc->sum + o->rc->lv); o->rv = max(o->rc->rv, o->rc->sum + o->lc->rv); o->v = max({o->lc->v, o->rc->v, o->lc->rv + o->rc->lv}); assert(o->v >= 0); } } void MO(int p, int v, seg *&o, int l=0, int r=n-1) { if (l > p || r<p) return; if (l == r) { o->v = v; pull(o); return; } int mid = l+r>>1; MO(p,v,o->lc,l,mid); MO(p,v,o->rc,mid+1,r); pull(o); } ll arr[maxn]; void build(seg * &o, int l=0, int r=n-1) { if (l == r) { o->v = arr[l]; pull(o); return; } int mid = l+r>>1; o->lc = new seg(); build(o->lc, l, mid); o->rc = new seg(); build(o->rc, mid+1, r); pull(o); } struct pt{ int x, y; ll v; }; struct Ev{ double sl; int a,b; }; int at[maxn]; signed main(){ IOS(); cin>>n; seg* root = new seg(); vector<pt> v(n); for (int i = 0; i<n; ++i) { cin>>v[i].x>>v[i].y>>v[i].v; } sort(v.begin(), v.end(), [&](pt a, pt b){return a.y!=b.y?a.y>b.y:a.x<b.x;}); for (int i = 0; i<n; ++i) { arr[i] = v[i].v; bug(v[i].v); at[i] = i; } build(root); bug(root->v, root->sum); bug(root->lv, root->rv); ll re = root->v; vector<Ev> qu; for (int i = 0; i<n; ++i) for (int j = i+1; j<n; ++j) { if (v[i].y != v[j].y) { qu.pb({-(v[i].x-v[j].x)/(double)(v[i].y-v[j].y), i, j}); } } sort(ALL(qu), [&](Ev a, Ev b){return a.sl < b.sl;}); for (Ev & e : qu) { bug("swapping", e.a, e.b); assert(abs(at[e.a]-at[e.b]) == 1); MO(at[e.a], v[e.b].v, root); MO(at[e.b], v[e.a].v, root); swap(at[e.a], at[e.b]); re = max(re, root->v); } cout<<re<<endl; }

컴파일 시 표준 에러 (stderr) 메시지

bulldozer.cpp:21:0: warning: "assert" redefined
 #define assert(...)
 
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from bulldozer.cpp:1:
/usr/include/assert.h:88:0: note: this is the location of the previous definition
 # define assert(expr)       \
 
bulldozer.cpp: In function 'void MO(int, int, seg*&, int, int)':
bulldozer.cpp:57:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l+r>>1;
               ~^~
bulldozer.cpp: In function 'void build(seg*&, int, int)':
bulldozer.cpp:68:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l+r>>1;
               ~^~
#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...