//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 2e9;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
#ifndef LOCAL
#include "aliens.h"
#endif
const int mxN=1e5+10,mxK=100+10;
int N,M,K;
ll dp[mxN][mxK];
vpi vec;
bool cmp(pi a, pi b){
if(a.fi!=b.fi) return a.fi<b.fi;
return a.se>b.se;
}
void filter(){ //change N and segs
sort(all(vec),cmp);
vpi vec2;
int mxr=-INF;
for(auto x: vec){
int l=x.fi,r=x.se;
if(r>mxr) vec2.pb(x);
ckmax(mxr,r);
}
vec.assign(all(vec2));
N=sz(vec);
}
ll sq(ll v){
return v*v;
}
//convex hull stuff
struct line{
ll a,b;
};
deque<line>st;
ld inter(line x, line y){
return ((ld)(y.b-x.b))/(x.a-y.a);
}
void add(ll a, ll b){
while(sz(st)>=2 &&
inter(st[sz(st)-1],line{a,b})<=inter(st[sz(st)-2],st[sz(st)-1]))
st.pop_back();
st.pb({a,b});
}
ll query(ll x){
while(sz(st)>=2
&& inter(st[0],st[1])<x) st.pop_front();
ll a=st[0].a,b=st[0].b;
return a*x+b;
}
//////////////
ll take_photos(int n, int m, int k, vi rr, vi cc) {
tie(N,M,K)={n,m,k};
FOR(i,0,N){
vec.eb(min(rr[i],cc[i]),max(rr[i],cc[i]));
}
filter();
memset(dp,0,sizeof(dp));
FOR(j,1,K+1){
st.clear(); //reinitialize convex hull
FOR(i,1,N+1){
int l=vec[i-1].fi,r=vec[i-1].se;
ll a=-2*(l-1);
ll b=dp[i-1][j-1] + sq(l-1);
if(i>=2) b-=sq(max(0,vec[i-2].se-vec[i-1].fi+1));
add(a,b);
dp[i][j]=sq(vec[i-1].se)+query(vec[i-1].se);
}
}
return dp[N][K];
}
#ifdef LOCAL
int main() {
boost; IO();
int N,M,K; cin>>N>>M>>K;
vi x(N),y(N);
FOR(i,0,N) cin>>x[i];
FOR(i,0,N) cin>>y[i];
cout << take_photos(N,M,K,x,y) << endl;
return 0;
}
#endif
//Change your approach
/*
5 7 2
0 4 4 4 4
3 4 6 5 6
*/
/*
2 6 2
1 4
4 1
*/
Compilation message
aliens.cpp: In function 'void filter()':
aliens.cpp:75:7: warning: unused variable 'l' [-Wunused-variable]
75 | int l=x.fi,r=x.se;
| ^
aliens.cpp: In function 'll take_photos(int, int, int, vi, vi)':
aliens.cpp:128:22: warning: unused variable 'r' [-Wunused-variable]
128 | int l=vec[i-1].fi,r=vec[i-1].se;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
2 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 4 |
3 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
4 |
Correct |
50 ms |
86400 KB |
Correct answer: answer = 12 |
5 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 52 |
6 |
Correct |
54 ms |
86380 KB |
Correct answer: answer = 210 |
7 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 88 |
8 |
Correct |
52 ms |
86380 KB |
Correct answer: answer = 7696 |
9 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 1 |
10 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 2374 |
11 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 9502 |
12 |
Correct |
51 ms |
86380 KB |
Correct answer: answer = 49 |
13 |
Correct |
49 ms |
86400 KB |
Correct answer: answer = 151 |
14 |
Correct |
48 ms |
86464 KB |
Correct answer: answer = 7550 |
15 |
Correct |
53 ms |
86508 KB |
Correct answer: answer = 7220 |
16 |
Correct |
71 ms |
86380 KB |
Correct answer: answer = 7550 |
17 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 10000 |
18 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 10000 |
19 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 624 |
20 |
Correct |
53 ms |
86380 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
86380 KB |
Correct answer: answer = 1 |
2 |
Incorrect |
54 ms |
86576 KB |
Wrong answer: output = 1, expected = 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
2 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 4 |
3 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
4 |
Correct |
50 ms |
86400 KB |
Correct answer: answer = 12 |
5 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 52 |
6 |
Correct |
54 ms |
86380 KB |
Correct answer: answer = 210 |
7 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 88 |
8 |
Correct |
52 ms |
86380 KB |
Correct answer: answer = 7696 |
9 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 1 |
10 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 2374 |
11 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 9502 |
12 |
Correct |
51 ms |
86380 KB |
Correct answer: answer = 49 |
13 |
Correct |
49 ms |
86400 KB |
Correct answer: answer = 151 |
14 |
Correct |
48 ms |
86464 KB |
Correct answer: answer = 7550 |
15 |
Correct |
53 ms |
86508 KB |
Correct answer: answer = 7220 |
16 |
Correct |
71 ms |
86380 KB |
Correct answer: answer = 7550 |
17 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 10000 |
18 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 10000 |
19 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 624 |
20 |
Correct |
53 ms |
86380 KB |
Correct answer: answer = 10000 |
21 |
Correct |
58 ms |
86380 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
54 ms |
86576 KB |
Wrong answer: output = 1, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
2 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 4 |
3 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
4 |
Correct |
50 ms |
86400 KB |
Correct answer: answer = 12 |
5 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 52 |
6 |
Correct |
54 ms |
86380 KB |
Correct answer: answer = 210 |
7 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 88 |
8 |
Correct |
52 ms |
86380 KB |
Correct answer: answer = 7696 |
9 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 1 |
10 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 2374 |
11 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 9502 |
12 |
Correct |
51 ms |
86380 KB |
Correct answer: answer = 49 |
13 |
Correct |
49 ms |
86400 KB |
Correct answer: answer = 151 |
14 |
Correct |
48 ms |
86464 KB |
Correct answer: answer = 7550 |
15 |
Correct |
53 ms |
86508 KB |
Correct answer: answer = 7220 |
16 |
Correct |
71 ms |
86380 KB |
Correct answer: answer = 7550 |
17 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 10000 |
18 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 10000 |
19 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 624 |
20 |
Correct |
53 ms |
86380 KB |
Correct answer: answer = 10000 |
21 |
Correct |
58 ms |
86380 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
54 ms |
86576 KB |
Wrong answer: output = 1, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
2 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 4 |
3 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
4 |
Correct |
50 ms |
86400 KB |
Correct answer: answer = 12 |
5 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 52 |
6 |
Correct |
54 ms |
86380 KB |
Correct answer: answer = 210 |
7 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 88 |
8 |
Correct |
52 ms |
86380 KB |
Correct answer: answer = 7696 |
9 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 1 |
10 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 2374 |
11 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 9502 |
12 |
Correct |
51 ms |
86380 KB |
Correct answer: answer = 49 |
13 |
Correct |
49 ms |
86400 KB |
Correct answer: answer = 151 |
14 |
Correct |
48 ms |
86464 KB |
Correct answer: answer = 7550 |
15 |
Correct |
53 ms |
86508 KB |
Correct answer: answer = 7220 |
16 |
Correct |
71 ms |
86380 KB |
Correct answer: answer = 7550 |
17 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 10000 |
18 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 10000 |
19 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 624 |
20 |
Correct |
53 ms |
86380 KB |
Correct answer: answer = 10000 |
21 |
Correct |
58 ms |
86380 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
54 ms |
86576 KB |
Wrong answer: output = 1, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
2 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 4 |
3 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 4 |
4 |
Correct |
50 ms |
86400 KB |
Correct answer: answer = 12 |
5 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 52 |
6 |
Correct |
54 ms |
86380 KB |
Correct answer: answer = 210 |
7 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 88 |
8 |
Correct |
52 ms |
86380 KB |
Correct answer: answer = 7696 |
9 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 1 |
10 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 2374 |
11 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 9502 |
12 |
Correct |
51 ms |
86380 KB |
Correct answer: answer = 49 |
13 |
Correct |
49 ms |
86400 KB |
Correct answer: answer = 151 |
14 |
Correct |
48 ms |
86464 KB |
Correct answer: answer = 7550 |
15 |
Correct |
53 ms |
86508 KB |
Correct answer: answer = 7220 |
16 |
Correct |
71 ms |
86380 KB |
Correct answer: answer = 7550 |
17 |
Correct |
49 ms |
86380 KB |
Correct answer: answer = 10000 |
18 |
Correct |
50 ms |
86380 KB |
Correct answer: answer = 10000 |
19 |
Correct |
48 ms |
86380 KB |
Correct answer: answer = 624 |
20 |
Correct |
53 ms |
86380 KB |
Correct answer: answer = 10000 |
21 |
Correct |
58 ms |
86380 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
54 ms |
86576 KB |
Wrong answer: output = 1, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |