#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1ll<<60);
bool cmp(pair<ll,ll> &a, pair<ll,ll> &b){
if(a.second == b.second)return a.first < b.first;
return a.second < b.second;
}
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pair<ll,ll>> 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(),cmp);
ll st = v[0].first, cu = v[0].second;
ll su = (cu-st+1)*(cu-st+1);
ll cn = 1;
for(int i = 0; i < n; ++i){
if(v[i].second <= cu)continue;
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 = INF;
while(l <= ri){
ll m = (l+ri)>>1;
ll st = v[0].first, cu = v[0].second;
ll su = (cu-st+1)*(cu-st+1);
ll cn = 1;
for(int i = 0; i < n; ++i){
if(v[i].second <= cu)continue;
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 = min(ans,su);
ri = m-1;
}
else{
l = m+1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 13, expected = 12 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
6 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 77263, expected = 71923 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 13, expected = 12 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 13, expected = 12 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 13, expected = 12 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 13, expected = 12 |
5 |
Halted |
0 ms |
0 KB |
- |