Submission #88913

#TimeUsernameProblemLanguageResultExecution timeMemory
88913heonKas (COCI17_kas)C++11
0 / 100
1388 ms395960 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...