This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(), order_of_key()
typedef long long ll;
typedef long double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<dd, dd> pdd;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<dd> vdd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vdd> vvdd;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vpdd> vvpdd;
typedef vector<bool> vb;
const int inf = 1 << 30;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ffor(i, a, b) for(ll i = a; i < b; i++)
#define forin(x, a) for (auto &x: a)
#define all(x) x.begin(), x.end()
#ifdef TEST
#define dbg(x) cout << #x << ": " << x << '\n';
#define dbgc(x) cout << #x << ":"; forin(a, x) { cout << " " << a; } cout << endl;
#define tassert(x) assert(x);
#else
#define dbg(x)
#define dbgc(x)
#define tassert(x)
#endif
auto cmp = [](pll a, pll b) {
return (a.first == b.first ? b.second < a.second : a.first < b.first);
};
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
set<pll, decltype(cmp)> segs(cmp);
rep(i, n) {
segs.emplace(min(r[i], c[i]), max(r[i], c[i]) + 1);
}
ll res = 0;
pll last = {-1, -1};
ll l;
vpll nsegs;
forin(seg, segs) {
if (seg.second <= last.second) {
continue;
}
nsegs.emplace_back(seg);
last = seg;
}
vvll dp(nsegs.size() + 1, vll(k + 1));
ffor(i, 1, nsegs.size() + 1) {
rep(j, k + 1) {
dp[i][j] = numeric_limits<ll>::max() >> 2;
if (!j) {
continue;
}
rep(t, i) {
dp[i][j] = min(dp[i][j], dp[t][j - 1] + (nsegs[i - 1].second - nsegs[t].first) * (nsegs[i - 1].second - nsegs[t].first) + (t && nsegs[t - 1].second > nsegs[t].first ? (nsegs[t - 1].second - nsegs[t].first) * (nsegs[t - 1].second - nsegs[t].first) : 0));
}
}
}
return dp.back().back();
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:34:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | #define ffor(i, a, b) for(ll i = a; i < b; i++)
......
71 | ffor(i, 1, nsegs.size() + 1) {
| ~~~~~~~~~~~~~~~~~~~~~~
aliens.cpp:71:3: note: in expansion of macro 'ffor'
71 | ffor(i, 1, nsegs.size() + 1) {
| ^~~~
aliens.cpp:58:6: warning: unused variable 'res' [-Wunused-variable]
58 | ll res = 0;
| ^~~
aliens.cpp:60:6: warning: unused variable 'l' [-Wunused-variable]
60 | ll l;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |