# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240909 | 2020-06-21T12:44:19 Z | SamAnd | Kas (COCI17_kas) | C++17 | 281 ms | 196492 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 502, M = 100005, INF = 1000000009; int n; int a[N]; int dp[N][M]; void solv() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n + 1; ++i) { for (int j = 0; j < M; ++j) { dp[i][j] = -INF; } } dp[n + 1][0] = 0; for (int i = n; i >= 1; --i) { for (int j = 0; j < M; ++j) { dp[i][j] = max(dp[i][j], dp[i + 1][j]); if (j + a[i] < M) dp[i][j] = max(dp[i][j], dp[i + 1][j + a[i]] + a[i]); if (abs(j - a[i]) < M) dp[i][j] = max(dp[i][j], dp[i + 1][abs(j - a[i])]); } } int ans = dp[1][0]; int s = 0; for (int i = 1; i <= n; ++i) s += a[i]; printf("%d\n", ans + s - ans * 2); } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING //ios_base::sync_with_stdio(false), cin.tie(0); solv(); return 0; } //while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 4608 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 4608 KB | Output is correct |
2 | Incorrect | 11 ms | 4736 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 4608 KB | Output is correct |
2 | Incorrect | 11 ms | 5120 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 5376 KB | Output is correct |
2 | Correct | 12 ms | 5888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 6016 KB | Output is correct |
2 | Correct | 12 ms | 5760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 14464 KB | Output is correct |
2 | Correct | 27 ms | 16384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 18304 KB | Output is correct |
2 | Correct | 34 ms | 20472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 128 ms | 79096 KB | Output is correct |
2 | Correct | 149 ms | 98628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 180 ms | 118136 KB | Output is correct |
2 | Correct | 228 ms | 157304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 261 ms | 177016 KB | Output is correct |
2 | Correct | 281 ms | 196492 KB | Output is correct |