제출 #270520

#제출 시각아이디문제언어결과실행 시간메모리
270520cgiosyBulldozer (JOI17_bulldozer)C++17
100 / 100
619 ms24184 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

struct node {
	ll mx, lm, rm, sum;
	node operator+(const node R) const {
		return {
			max({mx, R.mx, rm+R.lm}),
			max(lm, sum+R.lm),
			max(R.rm, rm+R.sum),
			sum+R.sum
		};
	}
};
struct spot {
	int x, y, w;
	bool operator<(const spot R) const {
		return x<R.x || x==R.x && y<R.y;
	}
};
struct event {
	int x, y, i;
	bool operator<(const event R) const {
		ll a=ll(x)*R.y, b=ll(y)*R.x;
		return a<b || a==b && i<R.i;
	}
};
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N, K=0;
	cin>>N;
	vector<spot> A(N);
	for(auto&[x,y,w]:A) cin>>x>>y>>w;
	sort(begin(A), end(A));

	vector<event> E(N*(N-1)/2);
	for(int i=0; i<N; i++) for(int j=0; j<i; j++)
		E[K++]={A[i].x-A[j].x, A[i].y-A[j].y, i<<16|j};
	sort(begin(E), end(E));

	vector<node> T(4096);
	auto upd=[&](int i, int x) {
		for(T[i|=2048]={x, x, x, x}; i>>=1;)
			T[i]=T[i*2]+T[i*2+1];
	};
	for(int i=0; i<N; i++) {
		int x=A[i].w;
		T[i+2048]={x, x, x, x};
	}
	for(int i=2048; i--;)
		T[i]=T[i*2]+T[i*2+1];

	ll mx=T[1].mx;
	vector<int> P(N);
	iota(begin(P), end(P), 0);
	for(int k=0; k<K; k++) {
		auto[x,y,t]=E[k];
		int i=t>>16, j=t&65535;
		swap(P[i], P[j]);
		upd(P[i], A[i].w);
		upd(P[j], A[j].w);
		if(k+1<K && ll(E[k].x)*E[k+1].y==ll(E[k+1].x)*E[k].y) continue;
		mx=max(mx, T[1].mx);
	}
	cout<<mx<<'\n';
}

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

bulldozer.cpp: In member function 'bool spot::operator<(spot) const':
bulldozer.cpp:19:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |   return x<R.x || x==R.x && y<R.y;
      |                   ~~~~~~~^~~~~~~~
bulldozer.cpp: In member function 'bool event::operator<(event) const':
bulldozer.cpp:26:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |   return a<b || a==b && i<R.i;
      |                 ~~~~~^~~~~~~~
#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...