# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
394279 |
2021-04-26T10:49:09 Z |
Drew_ |
Aliens (IOI16_aliens) |
C++17 |
|
3 ms |
2636 KB |
#include "aliens.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second
const int MAX = 1e5 + 7;
struct Line
{
ll m, c, ctr;
Line() : m(0), c(0), ctr(0) {}
Line(ll m, ll c, ll ctr) : m(m), c(c), ctr(ctr) {}
double inter(const Line &other) { return (double) (c - other.c) / (other.m - m); }
};
struct convex_hull
{
int sz = 0;
Line ar[MAX];
void clear() { sz = 0; }
bool cmp(Line a, Line b, Line c) { return a.inter(b) < b.inter(c); }
void addLine(ll m, ll c, ll ctr)
{
Line L(m, c, ctr);
while (sz >= 2 && !cmp(ar[sz-2], ar[sz-1], L))
sz--;
ar[sz++] = L;
}
pl query(ll x)
{
int l = 0, r = sz-1;
while (l < r)
{
int mid = (l + r) / 2;
if (ar[mid].inter(ar[mid+1]) >= x) r = mid;
else l = mid + 1;
}
return {ar[l].ctr + 1, ar[l].m * x + ar[l].c};
}
} cht;
vector<pl> ivl;
//cost for interval [i, j], assuming interval [0, i-1] have been fulfilled
/*
inline ll getCost(int i, int j)
{
ll res = 1LL * (ivl[j].s2 - ivl[i].f1 + 1) * (ivl[j].s2 - ivl[i].f1 + 1);
if (i)
{
if (ivl[i-1].s2 >= ivl[i].f1)
res -= 1LL * (ivl[i-1].s2 - ivl[i].f1 + 1) * (ivl[i-1].s2 - ivl[i].f1 + 1);
}
return res;
}
*/
pl dp[MAX];
ii solve(ll slope)
{
cht.clear();
cht.addLine(-2 * ivl[0].f1, ivl[0].f1 * ivl[0].f1, 0);
for (int i = 0; i < ivl.size(); ++i)
{
dp[i] = cht.query(ivl[i].s2);
dp[i].s2 += ivl[i].s2 * ivl[i].s2 - slope;
if (i+1 < ivl.size())
{
ll m = -2 * ivl[i+1].f1;
ll c = (ivl[i+1].f1 * ivl[i+1].f1) + dp[i].s2;
if (ivl[i+1].f1 < ivl[i].s2)
c -= (ivl[i].s2 - ivl[i+1].f1) * (ivl[i].s2 - ivl[i+1].f1);
ll ctr = dp[i].f1;
cht.addLine(m, c, ctr);
}
}
return dp[ivl.size() - 1];
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vector<ii> v(n);
for (int i = 0; i < n; ++i)
v[i] = {min(r[i], c[i]), max(r[i], c[i])};
sort(v.begin(), v.end(), [](const ii &x, const ii &y){
return x.f1 < y.f1 || (x.f1 == y.f1 && x.s2 > y.s2);
});
ivl.pb(v[0]);
for (int i = 1; i < n; ++i)
{
if (ivl.back().f1 <= v[i].f1 && v[i].s2 <= ivl.back().s2)
continue;
ivl.pb(v[i]);
}
for (auto &x : ivl)
x.s2++;
ll L = 0, R = 1e12;
k = min(k, (int)ivl.size());
while (L < R)
{
ll mid = (L + R) >> 1;
pl res = solve(mid);
if (res.f1 >= k) R = mid;
else L = mid + 1;
}
pl res = solve(L);
return k * L + res.s2;
}
/*
int main() {
int n, m, k;
assert(3 == scanf("%d %d %d", &n, &m, &k));
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
assert(2 == scanf("%d %d", &r[i], &c[i]));
}
long long ans = take_photos(n, m, k, r, c);
printf("%lld\n", ans);
return 0;
}
*/
Compilation message
aliens.cpp: In function 'std::pair<int, int> solve(long long int)':
aliens.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < ivl.size(); ++i)
| ~~^~~~~~~~~~~~
aliens.cpp:78:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | if (i+1 < ivl.size())
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Correct answer: answer = 4 |
2 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
3 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 12 |
5 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 52 |
6 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 210 |
7 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2636 KB |
Correct answer: answer = 7696 |
9 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
10 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 9502 |
12 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
17 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
18 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 624 |
20 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
2 |
Incorrect |
2 ms |
2636 KB |
Wrong answer: output = 2, expected = 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Correct answer: answer = 4 |
2 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
3 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 12 |
5 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 52 |
6 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 210 |
7 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2636 KB |
Correct answer: answer = 7696 |
9 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
10 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 9502 |
12 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
17 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
18 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 624 |
20 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
21 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
2 ms |
2636 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Correct answer: answer = 4 |
2 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
3 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 12 |
5 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 52 |
6 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 210 |
7 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2636 KB |
Correct answer: answer = 7696 |
9 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
10 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 9502 |
12 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
17 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
18 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 624 |
20 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
21 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
2 ms |
2636 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Correct answer: answer = 4 |
2 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
3 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 12 |
5 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 52 |
6 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 210 |
7 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2636 KB |
Correct answer: answer = 7696 |
9 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
10 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 9502 |
12 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
17 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
18 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 624 |
20 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
21 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
2 ms |
2636 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Correct answer: answer = 4 |
2 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
3 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 4 |
4 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 12 |
5 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 52 |
6 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 210 |
7 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 88 |
8 |
Correct |
3 ms |
2636 KB |
Correct answer: answer = 7696 |
9 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
10 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 9502 |
12 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 7550 |
17 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
18 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 624 |
20 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 10000 |
21 |
Correct |
2 ms |
2636 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
2 ms |
2636 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |