Submission #88912

# Submission time Handle Problem Language Result Execution time Memory
88912 2018-12-09T19:12:53 Z heon Kas (COCI17_kas) C++11
70 / 100
1139 ms 525312 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[1005][1005][55];
int dp2[1005][1005][55];

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

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

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, 0);
    cout << g(n, 0, 0, 0, 0, left) + left;
}
# Verdict Execution time Memory Grader output
1 Correct 385 ms 435320 KB Output is correct
2 Correct 381 ms 435320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 435320 KB Output is correct
2 Correct 404 ms 435320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 386 ms 435320 KB Output is correct
2 Correct 399 ms 435436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 435484 KB Output is correct
2 Correct 389 ms 435484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 405 ms 435484 KB Output is correct
2 Correct 416 ms 435484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 435484 KB Output is correct
2 Correct 399 ms 435484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 435484 KB Output is correct
2 Correct 442 ms 435484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 988 ms 525312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1097 ms 525312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1139 ms 525312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -