# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
942322 | KG07 | Aliens (IOI16_aliens) | C++17 | 1 ms | 508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
priority_queue<pair<int, int>> q;
for(int i = 0; i < n; i++){
if(r[i] > c[i])q.push(make_pair(-c[i], r[i]));
else q.push(make_pair(-r[i], c[i]));
}
vector<pair<int, int>> a;
a.push_back(make_pair(-q.top().first, q.top().second));
q.pop();
while(!q.empty()){
if(-q.top().first > a[a.size()-1].first && q.top().second > a[a.size()-1].second)a.push_back(make_pair(-q.top().first, q.top().second));
q.pop();
}
long long L = 0LL, R = 1LL * m * m;
while(true){
long long C = (L+R)/2;
vector<long long> b, d, x, y, z;
vector<pair<int, int>> h;
stack<long long> s;
b.push_back(0LL);
d.push_back(0LL);
x.push_back(0LL);
y.push_back(-2LL*(a[0].first-1));
z.push_back(1LL*(a[0].first-1)*(a[0].first-1));
h.push_back(make_pair(0, 0));
//cout << b[0] << " " << x[0]-C << " " << y[0] << " " << z[0] << "\n";
//cout << L << " " << C << " " << R << "\n";
int e = 0;
for(int i = 0; true; i++){
//cout << e-1 << "\n";
b.push_back(1000000LL*m*m);
d.push_back(0LL);
x.push_back(C+1LL*a[i].second*a[i].second);
y.push_back(-2LL*(a[i+1].first-1));
z.push_back(1LL*(a[i+1].first-1)*(a[i+1].first-1)-max(0LL, 1LL*(a[i].second-a[i+1].first+1))*max(0LL, 1LL*(a[i].second-a[i+1].first+1)));
/*for(int j = --e; j < h.size(); j++){
if(b[h[j].first]+x[i+1]+y[h[j].first]*a[i].second+z[h[j].first] <= b[i+1])d[i+1] = d[h[j].first]+1;
else break;
e++;
b[i+1] = min(b[i+1], b[h[j].first]+x[i+1]+y[h[j].first]*a[i].second+z[h[j].first]);
}*/
while(e+1<h.size() && h[e+1].second <= a[i].second)e++;
d[i+1] = d[h[e].first]+1;
b[i+1] = b[h[e].first]+x[i+1]+y[h[e].first]*a[i].second+z[h[e].first];
//cout << b[i+1] << " " << x[i+1] << " " << y[i+1] << " " << z[i+1] << " " << d[i+1] << "\n";
if(i+1==a.size())break;
while(h.size() > 0 && b[h[h.size()-1].first]+y[h[h.size()-1].first]*h[h.size()-1].second+z[h[h.size()-1].first] >=b[i+1]+y[i+1]*h[h.size()-1].second+z[i+1])h.pop_back();
if(h.size() == 0)h.push_back(make_pair(i+1, 0));
else h.push_back(make_pair(i+1, (b[i+1]+z[i+1]-b[h[h.size()-1].first]-z[h[h.size()-1].first])/(y[h[h.size()-1].first]-y[i+1])+1));
e = min(e, (int) h.size()-1);
//for(pair<int, int> t: h)cout << t.first << " " << y[t.first] << " " << z[t.first]+b[t.first] << " " << t.second << "\n";
//cout << b[i+1] << " " << x[i+1] << " " << y[i+1] << " " << z[i+1] << " " << d[i+1] << "\n";
}
if(L == R)return b[a.size()]-C*max(1LL*k, d[a.size()]);
if(d[a.size()] > k)L = (L+R+1)/2;
else R = C;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |