#include "aliens.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
bool cmp(pii x , pii y)
{
if(x.first == y.first)return x.second > y.second;
return x.first < y.first;
}
struct CHT{
vector<int>m;
vector<int>p;
int it=0;
bool check()
{
if(m.size() < 3)return false;
int l1 = m.size() - 3;
int l2 = m.size() - 2;
int l3 = m.size() - 1;
return 1LL*(p[l3] - p[l1]) * (m[l1] - m[l2]) < 1LL*(p[l2] - p[l1]) * (m[l1] - m[l3]);
}
void add(ll M,ll P)
{
m.push_back(M);
p.push_back(P);
while(check())
{
m.erase(m.end() - 2);
p.erase(p.end() - 2);
}
}
ll calc(ll x,int i)
{
return x * m[i] + p[i];
}
ll query(ll x)
{
if(it >= m.size() )it = m.size() - 1;
while(it < m.size() - 1 && calc(x , it) >= calc(x , it + 1 ) ){
++it;
}
return calc(x , it);
}
}ds[105];
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vector<pii>tmp;
vector<pii>v;
for(int i = 0 ; i < n ; ++i)
tmp.push_back( { min( r[i], c[i] ) , max( r[i] , c[i] ) } );
sort( tmp.begin() , tmp.end() , cmp );
int last = -1;
for(int i = 0 ; i < n ; ++i)
{
if(tmp[i].second <= last)continue;
v.push_back( tmp[i] );
last = max(last , tmp[i].second);
}
ll ans = (1LL <<61);
for(int i= 0 ; i <= k; ++i)
ds[i].add(-2 * (v[0].first - 1) , (v[0].first - 1) * (v[0].first - 1) );
n = v.size();
for(int i = 0 ; i < n ; ++i)
{
ll l = v[i].first;
ll r = v[i].second;
for(int j = k ; j >= 1 ; --j)
{
ll dp = ds[j - 1].query(r) + r * r;
if(i == n - 1)ans = min(ans , dp);
if(i < n - 1)
{
ll L = v[i + 1].first;
ll mx = max(0LL , r - L + 1);
ds[j].add( -2 * (L - 1) , (L - 1) * (L - 1) + dp - mx * mx );
}
}
}
return ans;
}
Compilation message
aliens.cpp: In member function 'long long int CHT::query(long long int)':
aliens.cpp:39:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it >= m.size() )it = m.size() - 1;
^
aliens.cpp:40:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(it < m.size() - 1 && calc(x , it) >= calc(x , it + 1 ) ){
^
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:69:9: warning: unused variable 'l' [-Wunused-variable]
ll l = v[i].first;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 5 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 41 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 71923 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 77137 |
8 |
Runtime error |
0 ms |
2028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 71923 |
27 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
0 ms |
2028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 71923 |
27 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
0 ms |
2028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 71923 |
27 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
0 ms |
2028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
22 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 71923 |
27 |
Correct |
0 ms |
2028 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
0 ms |
2028 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |