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 <bits/stdc++.h>
#include "aliens.h"
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 1e18;
const int mxN = 1e3+10, INF = 2e9;
ll n, m, dp[mxN][mxN];
array<int, 2> a[mxN];
ll sq(ll x){ return x*x; }
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c){
for (int i = 0; i < n; i++)
a[i] = {min(r[i], c[i]), max(r[i], c[i])};
sort(a, a+n);
vector<array<int, 2> > tmp;
for (int i = 0, mx = -1; i < n; i++){
if (a[i][1] > mx) tmp.pb(a[i]);
smax(mx, a[i][1]);
}
a[0] = {-1, -1};
for (int i = 0; i < tmp.size(); i++)
a[i+1] = tmp[i];
n = tmp.size();
for (int i = 1; i <= n; i++)
dp[i][0] = LINF;
for (int j = 1; j <= k; j++){
for (int i = 1; i <= n; i++){
dp[i][j] = LINF;
for (int t = 0; t < i; t++){
ll cost = sq(a[i][1] - a[t+1][0] + 1) - sq(max(0, a[t][1] - a[t+1][0] + 1));
smin(dp[i][j], dp[t][j-1] + cost);
}
}
}
ll ans = LINF;
for (int i = 0; i <= k; i++)
smin(ans, dp[n][i]);
return ans;
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < tmp.size(); i++)
| ~~^~~~~~~~~~~~
# | 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... |