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>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
const int MOD = 998244353;
ll N, M, K, A[1001];
ll DP[500][501];
ll solve(ll i, ll t) {
if(t < 0) return 1000000000LL * 1000000000LL;
if(i == N) return 0;
if(DP[i][t] != -1) return DP[i][t];
ll best = 1000000000LL * 1000000000LL;
for(ll l = i; l < N; l++) {
ll cur = (A[l] - A[i] + 1); cur *= cur;
best = min(best, cur + solve(l + 1, t - 1));
}
return DP[i][t] = best;
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
M = m, K = k; sort(r.begin(), r.end());
memset(DP, -1, sizeof DP);
for(auto u : r) {
if(N == 0 || A[N - 1] != u)
A[N++] = u;
}
ll best = solve(0, k);
return best;
}
# | 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... |