# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
109006 |
2019-05-04T00:31:03 Z |
bibabas |
Kas (COCI17_kas) |
C++14 |
|
414 ms |
88676 KB |
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
int INF = (int)2e9;
using namespace std;
template <class T>
istream& operator >>(istream &in, vector<T> &arr) {
for (T &cnt : arr) {
in >> cnt;
}
return in;
};
int n;
int dp[500][(int)5e4 + 1];
vi num;
int kek(int pos, int sum){
if (pos == n && sum == 0)
return 0;
if (pos == n)
return -INF;
if (dp[pos][sum] != -1)
return dp[pos][sum];
int a = kek(pos + 1, sum);
int b = num[pos] + kek(pos + 1, sum + num[pos]);
int c = kek(pos + 1, sum - num[pos]);
dp[pos][sum] = max({a, b, c});
return dp[pos][sum];
}
void solve() {
cin >> n;
num.assign(n, 0); cin >> num;
for (int i = 0; i <= n; ++i){
for (int j = 0; j <= (int)5e4; ++j){
dp[i][j] = -1;
}
}
int sum = 0;
for (int i = 0; i < n; ++i){
sum += num[i];
}
cout << sum - kek(0, 0);
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2560 KB |
Output is correct |
2 |
Correct |
4 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2560 KB |
Output is correct |
2 |
Correct |
5 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2560 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
5 ms |
3200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
5 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
8448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9352 KB |
Output is correct |
2 |
Correct |
11 ms |
10240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
39728 KB |
Output is correct |
2 |
Correct |
78 ms |
49548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
59332 KB |
Output is correct |
2 |
Correct |
284 ms |
78968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
414 ms |
88676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |