Submission #88913

# Submission time Handle Problem Language Result Execution time Memory
88913 2018-12-09T19:22:27 Z heon Kas (COCI17_kas) C++11
0 / 100
1388 ms 395960 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 dp2[100005][505];

int f(int n, int ind, int diff, int ostalo){  // minimiziraj ostatak
	if(ind == n && diff != 0) return MOD;
	if(ind == n && diff == 0) return ostalo;
	if(dp[diff][ind] != -1) return dp[diff][ind];
	return dp[diff][ind] = min({f(n, ind + 1, diff, ostalo + v[ind]), f(n, ind + 1, diff + v[ind], ostalo),
										f(n, ind + 1, abs(diff - v[ind]), ostalo)});
}

int g(int n, int ind, int diff, int ostalo, int target, int sum){  // maksimiziraj dobitak
	if(ind == n && ostalo != target) return 0;
	if(ind == n && diff != 0) return 0;
	if(ind == n && diff == 0 && ostalo == target) return sum / 2;
	if(dp2[diff][ind] != -1) return dp2[diff][ind];
	return dp2[diff][ind] = max({g(n, ind + 1, diff, ostalo + v[ind], target, sum), g(n, ind + 1, diff + v[ind], ostalo, target, sum + v[ind]),
										g(n, ind + 1, abs(diff - v[ind]), ostalo, target, sum + v[ind])});
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    v.resize(n);
    memset(dp, -1, sizeof(dp));
    memset(dp2, -1, sizeof(dp2));
    for(int i = 0; i < n; i++){
    	cin >> v[i];
    }
    int left = f(n, 0, 0, 0);
    cout << g(n, 0, 0, 0, left, 0) + left;
}
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 395576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 299 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 318 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 395908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 662 ms 395912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 721 ms 395912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1388 ms 395960 KB Output isn't correct
2 Halted 0 ms 0 KB -