제출 #405940

#제출 시각아이디문제언어결과실행 시간메모리
405940cgiosyAliens (IOI16_aliens)C++17
0 / 100
1 ms284 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

struct lr {
	int l, r;
	bool operator<(lr b) const { return l<b.l; }
};
ll pw(int x) { return ll(x)*x; }
ll take_photos(int N, int M, int K, vector<int> L, vector<int> R) {
	lr A[N];
	for(int i=0; i<N; i++) {
		int x=L[i], y=R[i];
		A[i]={min(x, y), max(x, y)};
	}
	sort(A, A+N);
	int N2=0;
	for(int i=1; i<N; i++) if(A[N2].r<A[i].r)
		A[N2+=A[N2].l<A[i].l]=A[i];
	N=N2+1;

	auto f=[&](ll m, int k=INT_MAX) {
		ll C[N+1];
		int D[N+1];
		C[0]=D[0]=0;
		for(int i=0; i<N; i++) {
			if(D[i]>k)
				return ll(-1);
			C[i+1]=LLONG_MAX;
			for(int j=0; j<=i; j++) {
				ll x=C[j]+pw(A[i].r-A[j].l+1)-m;
				if(x<C[i+1]) C[i+1]=x, D[i]=D[j]+1;
			}
		}
		return C[N];
	};
	ll l=-pw(M), r=0;
	while(l<r) {
		ll m=l+r+1>>1;
		if(~f(m, K)) l=m;
		else r=m-1;
	}
	return f(r)+K*r;
}

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

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:39:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |   ll m=l+r+1>>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...
#Verdict Execution timeMemoryGrader output
Fetching results...