이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using ld=long double;
using pp=pair<ll, ll>;
const int Nmax=100010;
ll N, NN, M, K, DP[Nmax], C[Nmax];
pp A[Nmax], B[Nmax];
struct line {
ll a, b;
int idx;
double s;
ll f(ll x) {return a*x+b;}
ld cross(line r) {return (ld)(b-r.b)/(r.a-a);}
};
vector<line> V;
void Dynamic(ll v) {
V.clear();
int pos=0;
for(int i=1; i<=N; i++) {
line tmp={-2*A[i].x, DP[i-1]+A[i].x*A[i].x-2*A[i].x, i-1, -1e30};
if(i && A[i].x<=A[i-1].y) tmp.b-=(A[i-1].y-A[i].x+1)*(A[i-1].y-A[i].x+1);
while(!V.empty()) {
tmp.s=tmp.cross(V.back());
if(V.back().s<tmp.s) break;
if(pos==V.size()-1) pos--;
V.pop_back();
}
V.push_back(tmp);
while(pos<V.size()-1 && V[pos+1].s<A[i].y) ++pos;
DP[i]=V[pos].f(A[i].y)+(A[i].y+1)*(A[i].y+1)+v;
C[i]=C[V[pos].idx]+1;
}
}
ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
NN=n, M=m, K=k;
for(int i=1; i<=NN; i++) {
B[i].x=min(r[i-1], c[i-1]), B[i].y=max(r[i-1], c[i-1]);
}
sort(B+1, B+NN+1, [](pp a, pp b) {return a.x!=b.x?a.x<b.x:a.y>b.y;});
for(int i=1; i<=NN; i++) {
if(N && B[i].y<=A[N].y) continue;
A[++N]=B[i];
}
K=min(K, N);
{
ll l=0, r=N+1, lv, rv;
for(ll s=0, e=M*M; s<=e;) {
ll mid=(s+e)/2;
Dynamic(mid);
if(C[N]==K) return DP[N]-mid*K;
else if(C[N]>K) {
s=mid+1;
if(r>C[N]) r=C[N], rv=DP[N]-mid*C[N];
}
else {
e=mid-1;
if(l<C[N]) l=C[N], lv=DP[N]-mid*C[N];
}
}
return rv+(lv-rv)/(r-l)*(r-K);
}
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'void Dynamic(ll)':
aliens.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if(pos==V.size()-1) pos--;
| ~~~^~~~~~~~~~~~
aliens.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(pos<V.size()-1 && V[pos+1].s<A[i].y) ++pos;
| ~~~^~~~~~~~~~~
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:66:33: warning: 'rv' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | return rv+(lv-rv)/(r-l)*(r-K);
| ^
aliens.cpp:66:18: warning: 'lv' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | return rv+(lv-rv)/(r-l)*(r-K);
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |