# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
393490 |
2021-04-23T15:27:10 Z |
usachevd0 |
Aliens (IOI16_aliens) |
C++17 |
|
2000 ms |
256 KB |
#include <bits/stdc++.h>
#ifndef DEBUG
#include "aliens.h"
#endif
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i) cerr << a[i];
cerr << endl;
}
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
for (auto& x : v) {
stream << x << ' ';
}
return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
return stream << p.first << ' ' << p.second;
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
const ll INF64 = 1e18;
const int maxN = 100005;
ll squared(ll a) {
return a * a;
}
struct pt {
int x, y;
pt(int _x = 0, int _y = 0): x(_x), y(_y) {}
pt operator + (const pt& p) const { return pt(x + p.x, y + p.y); }
pt operator - (const pt& p) const { return pt(x - p.x, y - p.y); }
};
ostream& operator << (ostream& stream, const pt& p) {
return stream << p.x << ' ' << p.y;
}
struct line {
ll k, b;
int info;
line() {}
line(ll _k, ll _b, int _info): k(_k), b(_b), info(_info) {}
ll y(ll x) {
return k * x + b;
}
};
double intersect_x(const line& a, const line& b) {
return -(a.b - b.b) / (double)(a.k - b.k);
}
namespace cht {
vector<line> ln;
vector<double> xl;
int ptr;
void init() {
ln.clear();
xl.clear();
ptr = 0;
}
void add_line(ll k, ll b, int info) {
line L(k, b, info);
while (!ln.empty()) {
double x = intersect_x(ln.back(), L);
if (x <= xl.back()) {
ln.pop_back();
xl.pop_back();
} else {
break;
}
}
xl.push_back(ln.empty() ? -INF64 : intersect_x(ln.back(), L));
ln.push_back(L);
}
pli gt(ll x) {
while (ptr + 1 < ln.size() && xl[ptr + 1] <= x) {
++ptr;
}
return {ln[ptr].y(x), ln[ptr].info};
}
}
ll dp[maxN];
int cnt[maxN];
ll take_photos(int n, int _m, int K, vector<int> _r, vector<int> _c) {
vector<pt> points(n);
for (int i = 0; i < n; ++i) {
points[i] = {_r[i], _c[i]};
if (points[i].x > points[i].y) {
swap(points[i].x, points[i].y);
}
}
sort(all(points), [&](const pt& P, const pt& Q) -> bool {
if (P.x != Q.x) return P.x < Q.x;
return P.y > Q.y;
});
vector<pt> a;
for (auto P : points) {
if (!a.empty() && P.y <= a.back().y) continue;
while (!a.empty() && P.x == a.back().x) {
a.pop_back();
}
a.push_back(P);
}
n = a.size();
// for (auto p : a) debug(p);
vector<ll> x(n), y(n);
for (int i = 0; i < n; ++i) {
x[i] = a[i].x;
y[i] = a[i].y;
}
vector<ll> I(n, 0);
for (int i = 1; i < n; ++i) {
if (x[i] > y[i - 1]) {
I[i] = 0;
} else {
I[i] = squared(y[i - 1] - x[i] + 1);
}
}
/*vector<vector<ll>> dp(n + 1, vector<ll>(K + 1, INF64));
fill(all(dp[0]), 0);
for (int k = 1; k <= K; ++k) {
cht::init();
for (int i = 1; i <= n; ++i) {
cht::add_line(-2 * x[i - 1], dp[i - 1][k - 1] + x[i - 1] * x[i - 1] - 2 * x[i - 1] - I[i - 1]);
dp[i][k] = cht::gt(y[i - 1]) + y[i - 1] * y[i - 1] + 2 * y[i - 1] + 1;
}
}*/
auto f = [&](ll lambda) -> pli {
fill(dp, dp + n + 1, INF64);
fill(cnt, cnt + n + 1, 0);
dp[0] = 0;
cht::init();
for (int i = 1; i <= n; ++i) {
cht::add_line(-2 * x[i - 1], dp[i - 1] + x[i - 1] * x[i - 1] - 2 * x[i - 1] - I[i - 1], cnt[i - 1]);
auto res = cht::gt(y[i - 1]);
dp[i] = res.fi + y[i - 1] * y[i - 1] + 2 * y[i - 1] + 1 + lambda;
cnt[i] = res.se + 1;
}
return {dp[n], cnt[n]};
};
ll ul = -1;
ll ur = 1e12 + 1337;
while (ur - ul > 1) {
ll um = (ul + um) >> 1;
if (f(um).se <= K) {
ur = um;
} else {
ul = um;
}
}
//debug(ur);
auto res = f(ur);
return res.fi - ur * res.se;
}
#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> r(n), c(n);
for (int i = 0; i < n; ++i) cin >> r[i] >> c[i];
cout << take_photos(n, m, k, r, c) << '\n';
return 0;
}
#endif
Compilation message
aliens.cpp: In function 'pli cht::gt(ll)':
aliens.cpp:117:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | while (ptr + 1 < ln.size() && xl[ptr + 1] <= x) {
| ~~~~~~~~^~~~~~~~~~~
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:191:17: warning: 'um' may be used uninitialized in this function [-Wmaybe-uninitialized]
191 | ll um = (ul + um) >> 1;
| ~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
256 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
2 |
Execution timed out |
2082 ms |
204 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
256 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Execution timed out |
2082 ms |
204 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
256 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Execution timed out |
2082 ms |
204 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
256 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Execution timed out |
2082 ms |
204 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
256 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Execution timed out |
2082 ms |
204 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |