이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of God
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 5e4 + 100;
const ll maxk = 105;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
vector<pll> vec;
ll dp[maxk][maxn], ps[maxn];
void solve(ll k, ll l, ll r, ll s, ll e){
if(l >= r) return;
ll mid = (l + r) >> 1;
ll opt = s;
dp[k][mid] = inf;
for(ll i = s; i < e && i <= mid; i++){
ll x = dp[k - 1][i - 1] + (vec[mid].F - vec[i].S + 1) * (vec[mid].F - vec[i].S + 1) - ps[i];
if(x < dp[k][mid]){
dp[k][mid] = x;
opt = i;
}
}
solve(k, l, mid, s, e);
solve(k, mid + 1, r, s, e);
return;
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pll> p(n);
vec.pb(Mp(-1, -1));
for(ll i = 0; i < n; i++){
if(r[i] < c[i]) swap(r[i], c[i]);
p[i] = Mp(c[i], -r[i]);
}
sort(all(p));
ll mx = -1;
for(ll i = 0; i < n; i++){
p[i].S *= -1;
if(p[i].S > mx){
vec.pb(Mp(p[i].S, p[i].F));
mx = p[i].S;
}
}
n = Sz(vec) - 1;
for(ll i = 2; i <= n; i++){
ll x = max(0ll, vec[i - 1].F - vec[i].S + 1);
ps[i] = x * x;
}
k = min(k, n);
fill(dp[0] + 1, dp[0] + n + 1, inf);
for(ll i = 1; i <= k; i++){
solve(i, 1, n + 1, 1, n + 1);
}
return dp[k][n];
}
/*int main(){
fast_io;
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'void solve(ll, ll, ll, ll, ll)':
aliens.cpp:29:5: warning: variable 'opt' set but not used [-Wunused-but-set-variable]
29 | ll opt = s;
| ^~~
# | 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... |