이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "aliens.h"
using namespace std;
#define int long long
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
const int inf = 1e18+10;
int n;
vector<pair<int,int>> pts;
int sol(int K) {
int dp[n][K+1];
for(int i = 0; i < n; i++) dp[i][0] = inf;
for(int k = 1; k <= K; k++) {
for(int i = 0; i < n; i++) {
dp[i][k] = inf;
int xi = pts[i].fr;
int yi = pts[i].sc;
for(int j = 0; j <= i; j++) {
int xj = pts[j].fr;
int yj = pts[j].sc;
if(j == 0) {
dp[i][k] = min(dp[i][k], (xi-yj+1)*(xi-yj+1));
}
else {
int xj1 = pts[j-1].fr;
int yj1 = pts[j-1].sc;
dp[i][k] = min(dp[i][k], dp[j-1][k-1] + xi*xi + 2*xi + 1 + yj*yj - 2*yj - 2*xi*yj - max((int)0,xj1-yj+1)*max((int) 0,xj1-yj+1));
}
}
}
}
return dp[n-1][K];
}
int take_photos(int32_t N, int32_t m, int32_t k, vector<int32_t> r, vector<int32_t> c) {
for(int i = 0; i < N; i++) {
int x = c[i];
int y = r[i];
if(x < y) swap(x,y);
pts.pb(mp(x,-y));
}
sort(all(pts));
stack<pair<int,int>> prt;
for(auto X : pts) {
int x = X.fr;
int y = -X.sc;
while(prt.size() && prt.top().sc >= y) prt.pop();
prt.push(mp(x,y));
}
pts.clear();
while(prt.size()) {
pts.pb(prt.top());
prt.pop();
}
sort(all(pts));
n = pts.size();
return sol(k);
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int sol(long long int)':
aliens.cpp:31:25: warning: unused variable 'yj1' [-Wunused-variable]
31 | int yj1 = pts[j-1].sc;
| ^~~
aliens.cpp:24:21: warning: unused variable 'xj' [-Wunused-variable]
24 | int xj = pts[j].fr;
| ^~
aliens.cpp:22:17: warning: unused variable 'yi' [-Wunused-variable]
22 | int yi = pts[i].sc;
| ^~
# | 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... |