제출 #522518

#제출 시각아이디문제언어결과실행 시간메모리
522518byunjaewooAliens (IOI16_aliens)C++17
컴파일 에러
0 ms0 KiB
#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; ll f(ll x) {return a*x+b;} ld cross(line r) {return (b-r.b)/(r.a-a);} }L[Nmax]; void Dynamic(ll v) { int fr=1, re=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}; if(i<N && A[i+1].x<=A[i].y) tmp.b-=(A[i].y-A[i+1].x+1)*(A[i].y-A[i+1].x+1); while(fr<re && L[re-1].cross(tmp)<=L[re-1].cross(L[re])) re--; L[++re]=tmp; while(fr<re && L[fr].f(A[i].y)>=L[fr+1].f(A[i].y)) fr++; DP[i]=L[fr].f(A[i].y)+A[i].y*A[i].y+v+2*A[i].y+1; if(L[fr].idx==0) C[i]=1; else C[i]=C[L[fr].idx-1]+1; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>NN>>M>>K; for(int i=1; i<=NN; i++) { int r, c; cin>>r>>c; B[i].x=min(r, c), B[i].y=max(r, c); } 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; while(N && A[N].y>=B[i].y) N--; 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) { cout<<DP[N]-mid*C[N]; return 0; } 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]; } } cout<<rv+(lv-rv)/(r-l)*(r-K); return 0; }

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

aliens.cpp: In function 'int main()':
aliens.cpp:64:32: warning: 'rv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     cout<<rv+(lv-rv)/(r-l)*(r-K);
      |                                ^
aliens.cpp:64:17: warning: 'lv' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     cout<<rv+(lv-rv)/(r-l)*(r-K);
      |              ~~~^~~~
/usr/bin/ld: /tmp/ccaQcSkj.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc67Mi1f.o:aliens.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccaQcSkj.o: in function `main':
grader.cpp:(.text.startup+0xf0): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status