///acum n*nlog (maxval) cu aliens
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
/**ifstream fin ("date.in");
ofstream fout ("date.out");
#define cin fin
#define cout fout**/
const int MAXN=1e5+10;
typedef long long ll;
ll INF=1e18;
int n,m,k;
ll dp[MAXN],cnt[MAXN];
vector <pair <int,int>> aux,v;
bool cmp (pair <int,int> a, pair <int,int> b){
if (a.first==b.first) return a.second>b.second;
return a.first<b.first;
}
ll solve (ll x){
dp[0]=cnt[0]=0;
for (int i=1;i<=n;++i){
dp[i]=INF;
cnt[i]=INF;
}
for (int i=1;i<=n;++i){
for (int t=i-1;t>=0;--t){
///am penalizare x
ll crt=x;
crt+=dp[t];
crt=crt+1LL*(v[i].second-v[t+1].first+1)*(v[i].second-v[t+1].first+1);
ll aux=max (0,v[t].second-v[t+1].first+1);
crt=crt-1LL*aux*aux;
if (dp[i]>crt){
dp[i]=crt;
cnt[i]=cnt[t]+1;
}
else{
if (dp[i]==crt){
cnt[i]=min (cnt[i],cnt[t]+1);
}
}
}
}
return cnt[n];
}
ll take_photos (int N, int M, int K, vector <int> r, vector <int> c){
n=N;
m=M;
k=K;
for (int i=0;i<n;++i){
r[i]++;
c[i]++;
if (r[i]>c[i]){
swap (r[i],c[i]);
}
aux.push_back ({r[i],c[i]});
}
sort (aux.begin (),aux.end (),cmp);
v.push_back ({0,0});
int cmax=0;
for (auto x:aux){
if (x.second>cmax){
cmax=x.second;
v.push_back (x);
}
}
n=v.size ()-1;
ll st=0,dr=INF,rez;
while (st<=dr){
ll mij=(st+dr)/2;
if (solve (mij)>k){
st=mij+1;
}
else{
dr=mij-1;
rez=mij;
}
}
solve (rez);
return dp[n]-cnt[n]*rez;
}
Compilation message (stderr)
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~| # | 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... |