#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
const int inf=1000001000;
const ll INF=10000000010000000;
const int MAXN=4010, K=4005;
int n, m, k;
pii A[MAXN];
pll dp[MAXN];
ll Inter(pll a, pll b){
if (a.first==b.first) return (a.second<=b.second?-INF:INF);
return (a.second-b.second)/(b.first-a.first) + ((a.second-b.second)%(b.first-a.first)>0);
}
struct CHT{
pair<ll, pll> A[MAXN];
int B[MAXN];
int L, R;
inline void Add(pll x, int y){
while (L<R && Inter(A[R-1].second, x)<A[R-1].first) R--;
B[R]=y;
if (L==R) A[R++]={-INF, x};
else A[R]={Inter(A[R-1].second, x), x}, R++;
}
inline pll Get(ll x){
while (L+1<R && A[L+1].first<=x) L++;
pll p=A[L].second;
return {p.first*x+p.second, B[L]};
}
} cht;
inline ll _sq(ll x){ return x*x;}
pll Solve(ll cost){
dp[0]={0, 0};
cht.L=cht.R=0;
for (int i=1; i<=n; i++){
ll val=_sq(A[i].first)+dp[i-1].first;
if (i!=1 && A[i].first<=A[i-1].second) val-=_sq(A[i-1].second-A[i].first+1);
cht.Add({2*A[i].first, -val}, dp[i-1].second);
pll p=cht.Get(A[i].second+1);
dp[i]={_sq(A[i].second+1)-p.first + cost, p.second+1};
}
return dp[n];
}
ll take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c) {
k=_k;
m=_m;
vector<pii> vec;
for (int i=0; i<_n; i++) vec.pb({min(r[i], c[i]), max(r[i], c[i])});
sort(all(vec), [](pii i, pii j){
if (i.second!=j.second) return i.second<j.second;
return i.first>j.first;
});
for (pii p:vec){
while (n && p.first<=A[n].first) n--;
A[++n]=p;
}
// for (int i=1; i<=n; i++) debugp(A[i])
k=min(k, n);
/*
memset(dp, 63, sizeof(dp));
for (int i=0; i<=k; i++) dp[0][i]=0;
for (int i=1; i<=n; i++){
for (int t=0; t<k; t++){
ll val=_sq(A[i].first)+dp[i-1][t];
if (i!=1 && A[i].first<=A[i-1].second) val-=_sq(A[i-1].second-A[i].first+1);
cht[t].Add({2*A[i].first, -val});
}
for (int t=1; t<=k; t++){
dp[i][t]=_sq(A[i].second+1)-cht[t-1].Get(A[i].second+1);
}
}
return dp[n][k];*/
ll dwn=-1, up=1e12;
while (up-dwn>1){
ll mid=(dwn+up)>>1;
pll p=Solve(mid);
if (p.second>=k) dwn=mid;
else up=mid;
}
pll p=Solve(dwn);
// debug(dwn)
// debugp(p)
return p.first - p.second*dwn;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
2 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 1 |
4 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 5 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 41 |
6 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
8 |
Incorrect |
1 ms |
332 KB |
Wrong answer: output = 729, expected = 764 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
332 KB |
Wrong answer: output = 729, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
332 KB |
Wrong answer: output = 729, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
332 KB |
Wrong answer: output = 729, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
332 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
332 KB |
Wrong answer: output = 729, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |