# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442974 | 2021-07-09T12:26:45 Z | zxcvbnm | Kas (COCI17_kas) | C++14 | 252 ms | 99228 KB |
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; const int MAXN = 505; const int MAXS = 100010; const int INF = 1e9; int n, sum, sol; int c[MAXN], memo[MAXN][MAXS/2]; int rek(int pos, int diff) { if (diff > sum / 2) return -INF; int& memo_ref = memo[pos][diff]; if (memo_ref != -1) return memo_ref; if (pos == n) return memo_ref = (diff != 0) * (-INF); return memo_ref = max(rek(pos + 1, diff), max(rek(pos + 1, diff + c[pos]) + c[pos], rek(pos + 1, abs(diff - c[pos])) + max(0, c[pos] - diff))); } int main(void) { memset(memo, -1, sizeof memo); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &c[i]); sum += c[i]; } sol = rek(0, 0); sol += sum - 2 * sol; printf("%d\n", sol); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 99012 KB | Output is correct |
2 | Correct | 43 ms | 99072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 99068 KB | Output is correct |
2 | Correct | 44 ms | 99084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 98972 KB | Output is correct |
2 | Correct | 43 ms | 99088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 98968 KB | Output is correct |
2 | Correct | 44 ms | 99040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 99012 KB | Output is correct |
2 | Correct | 47 ms | 99056 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 99104 KB | Output is correct |
2 | Correct | 46 ms | 99024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 99012 KB | Output is correct |
2 | Correct | 45 ms | 99044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 99020 KB | Output is correct |
2 | Correct | 64 ms | 99228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 99112 KB | Output is correct |
2 | Correct | 166 ms | 99120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 252 ms | 99108 KB | Output is correct |
2 | Correct | 237 ms | 99132 KB | Output is correct |