이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
struct line {
long long m, c;
};
struct CHT {
deque <line> lines;
bool cmp(const pair <long long, long long> &x, const pair <long long,long long> &y) {
return (x.first) * (y.second) < (x.second) * (y.first);
}
void push(line x) {
if(lines.size() && lines.back().m == x.m) {
if(x.c <= lines.back().c) lines.pop_back();
else return;
}
while(lines.size() >= 2 && cmp({lines.back().c - x.c, x.m - lines.back().m}, {lines[lines.size() - 2].c - lines.back().c, lines.back().m - lines[lines.size() - 2].m})) lines.pop_back();
lines.push_back(x);
}
long long query(long long x) {
while(lines.size() >= 2 && cmp({lines[1].c - lines[0].c, lines[0].m - lines[1].m}, {x, 1})) lines.pop_front();
return lines[0].m * x + lines[0].c;
}
};
long long take_photos(int n, int m, int k, vector<int> r,vector<int> c){
vector<pair<long long,long long>> seg1,seg;
for(int i = 0;i<n;i++){
seg1.push_back({min(c[i],r[i]),max(c[i],r[i])});
}
sort(seg1.begin(),seg1.end());
long long ma = -1e18;
for(int i = 0;i<n;i++){
if(seg1[i].second>ma){
seg.push_back(seg1[i]);
ma = seg1[i].second;
}
}
long long dp[seg.size()+1][k+1];
for(int i = 0;i<=k;i++)dp[0][i] = 0;
for(int i = 1;i<=seg.size();i++)dp[i][0] =1e18;
for(int j = 1;j<=k;j++){
CHT cht;
for(int i = 1;i<=seg.size();i++){
int e = i-1;
line pu = {(-2)*seg[e].first,dp[e][j-1]+seg[e].first*seg[e].first-2*seg[e].first+1-(e==0?0:max(0ll,seg[e-1].second-seg[e].first+1)*max(0ll,seg[e-1].second-seg[e].first+1))};
cht.push(pu);
dp[i][j] = cht.query(seg[i-1].second)+seg[i-1].second*seg[i-1].second+2*seg[i-1].second;
}
}
return dp[seg.size()][k];
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 1;i<=seg.size();i++)dp[i][0] =1e18;
| ~^~~~~~~~~~~~
aliens.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 1;i<=seg.size();i++){
| ~^~~~~~~~~~~~
# | 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... |