# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442980 |
2021-07-09T12:43:26 Z |
zxcvbnm |
Kas (COCI17_kas) |
C++14 |
|
343 ms |
441228 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxS = 1e5 + 5;
const int INF = 1e9 + 5;
int dp[55][1005][1005];
vector<int> a;
int n;
int go(int k, int x, int y) {
if (dp[k][x][y] != -1) {
return dp[k][x][y];
}
int& ret = dp[k][x][y];
if (k == n) {
return ret = (x == y ? 0 : -INF);
}
return ret = max({go(k+1, x, y), go(k+1, x+a[k], y)+a[k], go(k+1, x, y+a[k])+a[k]});
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
memset(dp, -1, sizeof dp);
cin >> n;
a.resize(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = accumulate(a.begin(), a.end(), 0);
int sol = go(0, 0, 0);
// cout << sol << "\n";
cout << (sol / 2) + (sum - (sol));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
217656 KB |
Output is correct |
2 |
Correct |
107 ms |
217672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
217660 KB |
Output is correct |
2 |
Correct |
100 ms |
217672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
217656 KB |
Output is correct |
2 |
Correct |
97 ms |
217640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
217608 KB |
Output is correct |
2 |
Correct |
99 ms |
217708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
217680 KB |
Output is correct |
2 |
Correct |
110 ms |
217640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
217672 KB |
Output is correct |
2 |
Correct |
132 ms |
217712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
217668 KB |
Output is correct |
2 |
Correct |
158 ms |
217600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
311 ms |
441204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
298 ms |
441176 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
343 ms |
441228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |