# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
88919 |
2018-12-09T19:43:35 Z |
heon |
Kas (COCI17_kas) |
C++11 |
|
570 ms |
198368 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
const int MOD = 1e9 + 7;
vi v;
int dp[100005][505];
int sum;
int f(int n, int ind, int diff, int prvi, int drugi){
if(ind == n && prvi != drugi) return 0;
if(ind == n && prvi == drugi) return prvi;
if(dp[diff][ind] != -1) return dp[diff][ind];
return dp[diff][ind] = max({f(n, ind + 1, diff + v[ind], prvi + v[ind], drugi), f(n, ind + 1, abs(diff - v[ind]), prvi, drugi + v[ind]),
f(n, ind + 1, diff, prvi, drugi)});
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
v.resize(n);
memset(dp, -1, sizeof(dp));
for(int i = 0; i < n; i++){
cin >> v[i];
}
sum = accumulate(all(v), 0);
int ret = f(n, 0, 0, 0, 0);
cout << ret + (sum - 2 * ret);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
198008 KB |
Output is correct |
2 |
Correct |
158 ms |
198188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
176 ms |
198188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
198188 KB |
Output is correct |
2 |
Incorrect |
170 ms |
198188 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
198196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
198196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
198228 KB |
Output is correct |
2 |
Correct |
169 ms |
198228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
198328 KB |
Output is correct |
2 |
Correct |
164 ms |
198328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
198328 KB |
Output is correct |
2 |
Correct |
204 ms |
198328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
278 ms |
198328 KB |
Output is correct |
2 |
Incorrect |
340 ms |
198328 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
570 ms |
198368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |