이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=4005;
const ll inf=1e18;
vector<vector<ll>> dp(mxn,vector<ll>(mxn,inf));
vector<int> x,y;
ll cost(int l,int r){
ll a=(y[r]-x[l]+1);
ll b=(l==1?0:max(0,y[l-1]-x[l]+1));
return a*a-b*b;
}
void go(int l,int r,int tl,int tr,int id){
if(l>r){
return;
}
int mid=(l+r)/2;
int pos=tl;
ll best=inf;
for(int i=tl;i<=min(mid-1,tr);i++){
ll cur=dp[i][id-1]+cost(i+1,mid);
if(cur<best){
pos=i;
best=cur;
}
}
dp[mid][id]=best;
go(l,mid-1,tl,pos,id);
go(mid+1,r,pos,tr,id);
}
ll solve(int n,int m,int k){
ll ans=inf;
dp[0][0]=0;
for(int t=1;t<=k;t++){
go(1,n,0,n,t);
ans=min(ans,dp[n][t]);
}
return ans;
}
ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
vector<pair<int,int>> vec(n);
for(int i=0;i<n;i++){
if(r[i]>c[i]) swap(r[i],c[i]);
vec[i]={c[i],r[i]};
}
sort(all(vec));
vector<pair<int,int>> st;
for(int i=0;i<n;i++){
while(!st.empty() and st.back().s>=vec[i].s){
st.pop_back();
}
st.push_back(vec[i]);
}
x.push_back(-1);
y.push_back(-1);
for(auto v:st){
x.push_back(v.s);
y.push_back(v.f);
}
return solve(st.size(),m,k);
}
//maybe its multiset not set
//yeeorz
//laborz
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'void setIO(std::string)':
aliens.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aliens.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |