이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1ll<<60);
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pair<int,int>> v(n);
for(int i = 0; i < n; ++i){
v[i] = {r[i],c[i]};
}
for(int i = 0; i < n; ++i){
if(v[i].first > v[i].second)swap(v[i].first,v[i].second);
}
sort(v.begin(),v.end());
int st = v[0].first, cu = v[0].second;
ll su = (cu-st+1)*(cu-st+1);
int cn = 1;
for(int i = 0; i < n; ++i){
if((v[i].second-v[i].first+1)*(v[i].second-v[i].first+1) < (v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1)){
cn++;
su+=(v[i].second-v[i].first+1)*(v[i].second-v[i].first+1);
st = v[i].first;
cu = v[i].second;
}
else{
su+=(v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1);
cu = v[i].second;
}
}
if(cn <= k)return su;
ll l = 0, ri = INF, ans = 0;
while(l <= ri){
ll m = (l+ri)>>1;
int st = v[0].first, cu = v[0].second;
ll su = (cu-st+1)*(cu-st+1);
int cn = 1;
for(int i = 0; i < n; ++i){
if((v[i].second-v[i].first+1)*(v[i].second-v[i].first+1)+m < (v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1)){
cn++;
su+=(v[i].second-v[i].first+1)*(v[i].second-v[i].first+1);
st = v[i].first;
cu = v[i].second;
}
else{
su+=(v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1);
cu = v[i].second;
}
}
if(cn <= k){
ans = su;
ri = m-1;
}
else{
l = m+1;
}
}
return ans;
}
# | 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... |