Submission #88920

# Submission time Handle Problem Language Result Execution time Memory
88920 2018-12-09T19:48:44 Z heon Kas (COCI17_kas) C++11
100 / 100
928 ms 198392 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 -MOD;
	if(ind == n && prvi == drugi) return 0;
	if(dp[diff][ind] != -1) return dp[diff][ind];
	return dp[diff][ind] = max({v[ind] + f(n, ind + 1, diff + v[ind], prvi + v[ind], drugi), v[ind] + 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 / 2 + (sum  - ret);
}
# Verdict Execution time Memory Grader output
1 Correct 183 ms 198008 KB Output is correct
2 Correct 168 ms 198012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 198200 KB Output is correct
2 Correct 152 ms 198200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 198236 KB Output is correct
2 Correct 163 ms 198236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 198268 KB Output is correct
2 Correct 152 ms 198268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 198268 KB Output is correct
2 Correct 163 ms 198268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 198268 KB Output is correct
2 Correct 156 ms 198268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 198308 KB Output is correct
2 Correct 150 ms 198308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 198392 KB Output is correct
2 Correct 218 ms 198392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 198392 KB Output is correct
2 Correct 360 ms 198392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 198392 KB Output is correct
2 Correct 928 ms 198392 KB Output is correct