# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43030 |
2018-03-08T07:10:35 Z |
nonocut |
Aliens (IOI16_aliens) |
C++14 |
|
6 ms |
728 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 = 1e3 + 5;
struct line {
ll m,c,val;
line(ll _m = 0, ll _c = 0, ll _val = 0) {
m = _m; c = _c; val = _val;
}
};
int n,m,k,sz;
pii p[maxn];
pii dp[maxn];
line cht[maxn];
ll getpow(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);
}
void solve(ll cost) {
int len = 0;
// printf("solve %lld\n",cost);
dp[sz] = {0,0};
for(int x=sz-1;x>=0;x--) {
//update
line t = line(-2*p[x].Y, dp[x+1].X - (x+1<sz ? getpow(max(0LL,p[x].Y-p[x+1].X+1)):0) + p[x].Y*p[x].Y, dp[x+1].Y+1);
cht[++len] = t;
// while(len>=3) {
// if(cut(len-1,len)>=cut(len-2,len)) cht[len-1] = cht[len], len--;
// else break;
// }
// for(int i=1;i<=len;i++) printf("{%lld, %lld} ",cht[i].m,cht[i].c);
// printf("\n");
//query
// int l = 2, r = len, mid, pos = 1;
// while(l<=r) {
// mid = (l+r)/2;
// if(cut(mid-1,mid)<=p[x].X-1) {
// pos = mid;
// l = mid+1;
// }
// else r = mid-1;
// }
int pos = 1;
for(int i=1;i<=len;i++) {
if(cht[i].m*(p[x].X-1)+cht[i].c < cht[pos].m*(p[x].X-1)+cht[pos].c) pos = i;
}
dp[x] = {cht[pos].m * (p[x].X-1) + cht[pos].c + (p[x].X-1)*(p[x].X-1) + cost, cht[pos].val};
// printf("dp %d = {%lld, %lld}\n",x,dp[x].X,dp[x].Y);
}
}
bool cmp(pii x, pii y) {
if(x.X!=y.X) return x.X<y.X;
return x.Y>y.Y;
}
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;
for(int i=0;i<n;i++) {
if(p[i].Y<=cur) continue;
p[sz++] = p[i];
cur = p[i].Y;
}
//solve
ll l = 0, r = 1e8, mid;
ll ans;
while(l<r) {
mid = (l+r)/2;
solve(mid);
if(dp[0].Y<=k) r = mid;
else l = mid+1;
}
solve(l);
return dp[0].X - l*dp[0].Y;
}
Compilation message
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:87:5: warning: unused variable 'ans' [-Wunused-variable]
ll ans;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
352 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
428 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
496 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
548 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
4 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 5 |
5 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 41 |
6 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 71923 |
7 |
Correct |
3 ms |
728 KB |
Correct answer: answer = 77137 |
8 |
Incorrect |
6 ms |
728 KB |
Wrong answer: output = 925, expected = 764 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
352 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
428 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
496 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
548 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
24 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 5 |
25 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 41 |
26 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
728 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
6 ms |
728 KB |
Wrong answer: output = 925, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
352 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
428 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
496 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
548 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
24 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 5 |
25 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 41 |
26 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
728 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
6 ms |
728 KB |
Wrong answer: output = 925, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
352 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
428 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
496 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
548 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
24 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 5 |
25 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 41 |
26 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
728 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
6 ms |
728 KB |
Wrong answer: output = 925, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
352 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
428 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
496 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
548 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
548 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
728 KB |
Correct answer: answer = 1 |
24 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 5 |
25 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 41 |
26 |
Correct |
2 ms |
728 KB |
Correct answer: answer = 71923 |
27 |
Correct |
3 ms |
728 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
6 ms |
728 KB |
Wrong answer: output = 925, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |