이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
bool compare(pair<int,int> a,pair<int,int> b){
if(a.fi!=b.fi) return a.fi<b.fi;
return a.se>b.se;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
pair<int,int> tab[n];
for (int i = 0; i < n; ++i)
{
tab[i]={min(r[i],c[i]),max(r[i],c[i])};
}
sort(tab,tab+n,compare);
vector<pair<int,int>> v;
v.push_back({-1,-1});
for (int i = 0; i < n; ++i)
{
if(v.empty()) v.push_back(tab[i]);
else if(v.back().se>=tab[i].se) continue;
else v.push_back(tab[i]);
}
n=v.size();
long long dp[n+1][k+1];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j <= k; ++j)
{
if(i) dp[i][j]=1e18;
else dp[i][j]=0;
}
}
for (int i = 1; i < n; ++i)
{
int lst=v[i].se;
int cur=1;
for (int j = i; j >= 0; j--)
{
if(j==0) dp[i][1]=cur*cur;
else{
cur+=lst-v[j].fi;
lst=v[j].fi;
for (int t = 1; t <= k; ++t)
{
dp[i][t]=min(dp[i][t],dp[j-1][t-1]+cur*cur-max(0,v[j-1].se-v[j].fi+1)*max(0,v[j-1].se-v[j].fi+1));
//cout <<j<<" "<<t<<" "<<dp[i][t]<<" "<<dp[j-1][t-1]<<" "<<cur<<endl;
}
}
}
}
long long ans=m*m;
for (int i = 1; i <= k; ++i)
{
ans=min(ans,dp[n-1][i]);
}
return ans;
}
/*int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m, k;
assert(3 == scanf("%d %d %d", &n, &m, &k));
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
assert(2 == scanf("%d %d", &r[i], &c[i]));
}
long long ans = take_photos(n, m, k, r, c);
printf("%lld\n", ans);
return 0;
}*/
# | 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... |