Submission #732043

# Submission time Handle Problem Language Result Execution time Memory
732043 2023-04-28T09:52:17 Z vjudge1 Kas (COCI17_kas) C++11
70 / 100
2000 ms 119452 KB
#include <bits/stdc++.h>
using namespace std;

map<array<int, 4>, bool> done;
const int MxN = 220;
int n, answer;
int a[MxN];

void rec(int state, int kang, int pun, int remain){
	if(done[{state, kang, pun, remain}]){
		return ;
	}
	done[{state, kang, pun, remain}] = true;
	if(state == n + 1){
		if(kang == pun && kang != 0){
			answer = max(answer, kang);
		}
		return ;
	}
	rec(state + 1, kang + a[state], pun, remain);
	rec(state + 1, kang, pun + a[state], remain);
	rec(state + 1, kang, pun, remain + a[state]);
}

int main() {
	cin.tie(nullptr)->ios::sync_with_stdio(false);
	int q = 1;
	//cin >> q;
	while(q--){
		done.clear();
		cin >> n;
		int all = 0;
		for(int i=1; i<=n; ++i){
			cin >> a[i];
			all += a[i];
		}
		answer = 0;
		rec(1, 0, 0, 0);
		cout << answer + (all - answer * 2) << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3624 KB Output is correct
2 Correct 14 ms 2368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3376 KB Output is correct
2 Correct 30 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2624 KB Output is correct
2 Correct 63 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 9728 KB Output is correct
2 Correct 79 ms 9868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 11244 KB Output is correct
2 Correct 494 ms 41660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1279 ms 79020 KB Output is correct
2 Correct 501 ms 36984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1825 ms 119452 KB Output is correct
2 Correct 1737 ms 119424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2041 ms 107004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 113564 KB Time limit exceeded
2 Halted 0 ms 0 KB -