Submission #88915

# Submission time Handle Problem Language Result Execution time Memory
88915 2018-12-09T19:31:33 Z heon Kas (COCI17_kas) C++11
40 / 100
544 ms 198508 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 f(int n, int ind, int diff, int sum){
	if(ind == n && diff != 0) return 0;
	if(ind == n && diff == 0) return sum / 2;
	if(dp[diff][ind] != -1) return dp[diff][ind];
	return dp[diff][ind] = max({f(n, ind + 1, diff + v[ind], sum + v[ind]), f(n, ind + 1, abs(diff - v[ind]), sum + v[ind]),
							f(n, ind + 1, diff, sum)});
}

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];
    }
    int sum = accumulate(all(v), 0);
    int ret = f(n, 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 151 ms 198012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 198088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 152 ms 198132 KB Output is correct
2 Incorrect 158 ms 198188 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 198188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 198188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 152 ms 198228 KB Output is correct
2 Correct 167 ms 198228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 198292 KB Output is correct
2 Correct 150 ms 198292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 297 ms 198292 KB Output is correct
2 Correct 180 ms 198292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 198308 KB Output is correct
2 Incorrect 356 ms 198348 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 544 ms 198508 KB Output isn't correct
2 Halted 0 ms 0 KB -