# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173845 | tourist | K blocks (IZhO14_blocks) | C++14 | 5 ms | 504 KiB |
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 <iostream>
#include <map>
#include <vector>
using namespace std;
#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;
const int N = 109;
const int mod = 1e9 + 7; /// ANOTHER HASH MOD: 228228227
const int prime = 29; /// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);
int n, k, mx[N][N];
int a[N], ans, dp[N][N];
map < pair < int, int >, int > mp;
inline int read() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
return 0;
}
void calc(int l, int k, int sum) {
if (k == 1) {
ans = min(ans, mx[l][n] + sum);
return;
}
pair < int, int > check = {l, k};
if (mp.count(check)) {
return;
}
mp[check] = 1;
for (int i = l; i <= n - k + 1; i++) {
calc(i + 1, k - 1, sum + mx[l][i]);
}
}
inline int solve() {
ans = INF;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
mx[i][j] = max(mx[i][j - 1], a[j]);
}
}
calc(1, k, 0);// TODO: WHY TLE?
cout << dp[n][k] << endl;
return 0;
}
int main() {
int t = 1;
while (t--) {
read();
if (n >= N) {
cout << "FUCK YOU" << endl;
return 0;
}
solve();
}
}
Compilation message (stderr)
# | 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... |