이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3, MOD = 1e9 + 7;
typedef long long ll;
#include "aliens.h"
int n,m,k;
vector<pair<ll,ll>> a,x;
ll res;
ll dp[N],L[N],R[N];
int col[N];
ll f(ll pen){
dp[0] = 0;
col[0] = 0;
for(int i = 1;i <= n;i++){
for(int j = i;j >= 1;j--){
if(j == i || dp[j - 1] + (R[i] - L[j] + 1) * (R[i] - L[j] + 1) -
max(0ll, R[j - 1] - L[j] + 1) * max(0ll, R[j - 1] - L[j] + 1) + pen < dp[i]){
dp[i] = (dp[j - 1] + (R[i] - L[j] + 1) * (R[i] - L[j] + 1) -
max(0ll, R[j - 1] - L[j] + 1) * max(0ll, R[j - 1] - L[j] + 1) + pen);
col[i] = col[j - 1] + 1;
}
}
}
res = dp[n];
return col[n];
}
long long take_photos(int nn,int mm,int kk,vector<int> rr,vector<int> cc){
n = nn;
m = mm;
k = kk;
for(int i = 1;i <= n;i++){
int l = rr[i - 1],r = cc[i - 1];
++l;++r;
if(l > r){
swap(l,r);
}
a.push_back({l,-r});
}
sort(a.begin(),a.end());
int mx = 0;
x.push_back({0,0});
for(auto [l,r]:a){
r = -r;
if(r > mx){
mx = r;
x.push_back({l,r});
}
}
sort(x.begin(),x.end());
n = (int)x.size() - 1;
for (int i = 1; i <= n; i++) {
L[i] = x[i].first;
R[i] = x[i].second;
}
ll l = -1,r = 1e15;
k = min(k,n);
while(r - l > 1) {
ll mid = (l + r) >> 1;
if (f(mid) >= k) {
l = mid;
} else {
r = mid;
}
}
ll x = f(l);
return res - k * 1ll * l;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:70:8: warning: unused variable 'x' [-Wunused-variable]
70 | ll x = f(l);
| ^
# | 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... |