#pragma GCC optimize ("O3")
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define ppb pop_back
#define ft first
#define sd second
#define readf freopen("input.txt", "r", stdin)
#define writef freopen("output.txt", "w", stdout)
#define files readf; writef
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int Z = 999;
const int N = (int)1e6 + 228;
const int INF = (int)1e9 + 5;
const int MOD = (int)1e9 + 7;
int main() {
SWS;
srand(time(0));
//files;
int n, sum = 0;
cin >> n;
vector<int> a(n + 2);
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
vector<int> ans;
for (a[n + 1] = 0; a[n + 1] <= sum; a[n + 1]++) {
bool flag = true;
//cout << a[n + 1] << endl;
for (int i = 1; i <= n + 1; i++) {
vector<int> v;
v.pb(0);
int cur_sum = 0;
for (int j = 1; j < i; j++) {
v.pb(a[j]);
cur_sum += a[j];
}
for (int j = i + 1; j <= n + 1; j++) {
v.pb(a[j]);
cur_sum += a[j];
}
vector<vector<bool> > f(n + 1, vector<bool> (cur_sum + 1, false));
f[0][0] = true;
for (int j = 1; j <= n; j++) {
for (int q = 0; q <= cur_sum; q++) {
f[j][q] = f[j - 1][q];
if (q - v[j] >= 0 && f[j - 1][q - v[j]]) f[j][q] = true;
}
}
bool nf = false;
for (int j = 1; j <= n; j++) {
if (cur_sum % 2 == 0 && f[j][cur_sum / 2]) nf = true;
}
flag &= nf;
}
if (flag) {
ans.pb(a[n + 1]);
}
}
cout << ans.size() << "\n";
for (int i : ans) {
cout << i << ' ';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
58 ms |
412 KB |
Output is correct |
5 |
Correct |
896 ms |
388 KB |
Output is correct |
6 |
Correct |
20 ms |
376 KB |
Output is correct |
7 |
Correct |
26 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1035 ms |
476 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |