# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43040 |
2018-03-08T08:44:53 Z |
top34051 |
Aliens (IOI16_aliens) |
C++14 |
|
4 ms |
2996 KB |
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define X first
#define Y second
const int maxn = 1e5 + 5;
struct line {
ll m,c,id;
line(ll _m = 0, ll _c = 0, int _id = 0) {
m = _m; c = _c; id = _id;
}
};
int n,m,k;
pii p[maxn];
int r[maxn], c[maxn];
ll dp[maxn], cnt[maxn];
line cht[maxn];
bool cmp(pii x, pii y) {
if(x.X!=y.X) return x.X<y.X;
return x.Y>y.Y;
}
ll p2(ll x) { return x*x; }
double cut(int x, int y) {
if(x==0 || y==0) return -2e16;
return (double)(cht[y].c-cht[x].c)/(cht[x].m-cht[y].m);
}
int solve(ll cost) {
int len = 0;
for(int x=1;x<=n;x++) {
cht[++len] = line(-2*r[x], p2(r[x]) + dp[x-1] - p2(max(0,c[x-1]-r[x])),x-1);
while(len>=3 && cut(len-1,len)<=cut(len-2,len)) cht[len-1] = cht[len], len--;
int l = 2, r = len, mid, pos = 1;
while(l<=r) {
int mid = (l+r)/2;
if(cut(mid-1,mid)<=c[x]) pos = mid, l = mid+1;
else r = mid-1;
}
dp[x] = cht[pos].m*c[x] + cht[pos].c + p2(c[x]) + cost;
cnt[x] = cnt[cht[pos].id] + 1;
// printf("dp %d %d = %lld\n",x,t,dp[x][t]);
}
return cnt[n];
}
long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) {
n = N; m = M; k = K;
//prep
for(int i=0;i<n;i++) {
p[i] = {R[i],C[i]};
if(p[i].X>p[i].Y) swap(p[i].X,p[i].Y);
}
sort(p,p+n,cmp);
ll cur = -1, sz = 0;
for(int i=0;i<n;i++) {
if(p[i].Y<=cur) continue;
sz++;
r[sz] = p[i].X; c[sz] = p[i].Y+1;
cur = p[i].Y;
}
n = sz;
//bsearch
ll l = 0, r = 1e12, mid, pos;
while(l<=r) {
mid = (l+r)/2;
if(solve(mid)<=k) pos = mid, r = mid-1;
else l = mid+1;
}
solve(pos);
return dp[n] - pos*k;
}
Compilation message
aliens.cpp: In function 'int solve(long long int)':
aliens.cpp:41:29: warning: unused variable 'mid' [-Wunused-variable]
int l = 2, r = len, mid, pos = 1;
^
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:77:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
solve(pos);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Correct answer: answer = 4 |
2 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
4 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 12 |
5 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 52 |
6 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 210 |
7 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 7696 |
9 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 1 |
10 |
Correct |
3 ms |
2852 KB |
Correct answer: answer = 2374 |
11 |
Correct |
3 ms |
2908 KB |
Correct answer: answer = 9502 |
12 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 49 |
13 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 151 |
14 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7550 |
15 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7220 |
16 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 7550 |
17 |
Correct |
4 ms |
2996 KB |
Correct answer: answer = 10000 |
18 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
19 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 624 |
20 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
2 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
4 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 5 |
5 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 41 |
6 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 71923 |
7 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 77137 |
8 |
Incorrect |
4 ms |
2996 KB |
Wrong answer: output = 741, expected = 764 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Correct answer: answer = 4 |
2 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
4 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 12 |
5 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 52 |
6 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 210 |
7 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 7696 |
9 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 1 |
10 |
Correct |
3 ms |
2852 KB |
Correct answer: answer = 2374 |
11 |
Correct |
3 ms |
2908 KB |
Correct answer: answer = 9502 |
12 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 49 |
13 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 151 |
14 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7550 |
15 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7220 |
16 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 7550 |
17 |
Correct |
4 ms |
2996 KB |
Correct answer: answer = 10000 |
18 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
19 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 624 |
20 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
21 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
22 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 4 |
23 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
24 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 5 |
25 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 41 |
26 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
4 ms |
2996 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Correct answer: answer = 4 |
2 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
4 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 12 |
5 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 52 |
6 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 210 |
7 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 7696 |
9 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 1 |
10 |
Correct |
3 ms |
2852 KB |
Correct answer: answer = 2374 |
11 |
Correct |
3 ms |
2908 KB |
Correct answer: answer = 9502 |
12 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 49 |
13 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 151 |
14 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7550 |
15 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7220 |
16 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 7550 |
17 |
Correct |
4 ms |
2996 KB |
Correct answer: answer = 10000 |
18 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
19 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 624 |
20 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
21 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
22 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 4 |
23 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
24 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 5 |
25 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 41 |
26 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
4 ms |
2996 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Correct answer: answer = 4 |
2 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
4 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 12 |
5 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 52 |
6 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 210 |
7 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 7696 |
9 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 1 |
10 |
Correct |
3 ms |
2852 KB |
Correct answer: answer = 2374 |
11 |
Correct |
3 ms |
2908 KB |
Correct answer: answer = 9502 |
12 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 49 |
13 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 151 |
14 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7550 |
15 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7220 |
16 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 7550 |
17 |
Correct |
4 ms |
2996 KB |
Correct answer: answer = 10000 |
18 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
19 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 624 |
20 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
21 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
22 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 4 |
23 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
24 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 5 |
25 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 41 |
26 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
4 ms |
2996 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
Correct answer: answer = 4 |
2 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
3 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 4 |
4 |
Correct |
3 ms |
2784 KB |
Correct answer: answer = 12 |
5 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 52 |
6 |
Correct |
3 ms |
2804 KB |
Correct answer: answer = 210 |
7 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 7696 |
9 |
Correct |
3 ms |
2848 KB |
Correct answer: answer = 1 |
10 |
Correct |
3 ms |
2852 KB |
Correct answer: answer = 2374 |
11 |
Correct |
3 ms |
2908 KB |
Correct answer: answer = 9502 |
12 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 49 |
13 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 151 |
14 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7550 |
15 |
Correct |
3 ms |
2924 KB |
Correct answer: answer = 7220 |
16 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 7550 |
17 |
Correct |
4 ms |
2996 KB |
Correct answer: answer = 10000 |
18 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
19 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 624 |
20 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 10000 |
21 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
22 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 4 |
23 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 1 |
24 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 5 |
25 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 41 |
26 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
2996 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
4 ms |
2996 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |