/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define F first
#define mp make_pair
#define S second
#define pii pair <int, int >
#define pll pair <long long, long long >
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
#define bo cout << "OK" << endl;
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 1e6 + 5;
const ll mod = 1e9 + 7;
const ll INF = 1e10;
const ll M = (1 << 17) + 5;
const ll LL = 1;
const ll p = 31;
bool ok;
inline ll gcd (int a, int b) {
while (b) {
a %= b;
swap (a, b);
}
return a;
}
inline ll bp (int a, int b) {
if(b == 0) return 1;
else if(b % 2) return ((bp(a, b - 1) % mod) * a) % mod;
else {
int c = bp(a, b / 2) % mod;
return (c * c) % mod;
}
}
inline ll sum(int x) {
int res = 0;
while(x) {
res += x % 10;
x /= 10;
}
return res;
}
ll q, n, m, k, a[N];
int dp[500 * 500];
string s, s1, s2;
bool check2(vector < int > v) {
int sum1 = 0;
bool ret = 0;
for(int i = 0; i < v.size(); i++) {
sum1 += v[i];
}
if(sum1 % 2 == 0) {
sum1 /= 2;
for(int i = 0; i <= sum1; i++) {
dp[i] = 0;
}
dp[0] = 1;
for (int i = 0; i < v.size(); ++i) {
for (int j = sum1; j >= 0; --j) {
if (dp[j] == 1 && j + v[i] <= sum1) {
dp[j + v[i]] = 1;
}
}
}/*
cout << "Sum: " << sum1 * 2 << "\n";
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << " --> " << dp[sum1] << "\n";*/
if (dp[sum1] == 1)
return 1;
}
return 0;
}
bool check(int val) {
a[0] = val;
//cout << "Val: " << val << "\n";
for(int i = 0; i <= n; i++) {
vector < int > v;
for(int j = 0; j <= n; j++) {
if(i != j) {
v.pb(a[j]);
//cout << a[j] << " ";
}
}
//cout << endl;
if(!check2(v)) return 0;
}
return 1;
}
main()
{
//file("B");
ios;
cin >> n;
int sum = 0, mn = 501;
for(int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
sum += a[i];
}
//sort(a + 1, a + n + 1);
vector < int > ans;
for(int tmp = 1; tmp <= sum - mn; tmp++) {
if(check(tmp)) ans.pb(tmp);
}
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); i++) {
cout << ans[i] << " ";
}
}
Compilation message
bootfall.cpp: In function 'bool check2(std::vector<long long int>)':
bootfall.cpp:79:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
bootfall.cpp:88:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
bootfall.cpp:78:10: warning: unused variable 'ret' [-Wunused-variable]
78 | bool ret = 0;
| ^~~
bootfall.cpp: At global scope:
bootfall.cpp:124:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
124 | main()
| ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:141:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int i = 0; i < ans.size(); i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
57 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
492 KB |
Output is correct |
14 |
Correct |
63 ms |
364 KB |
Output is correct |
15 |
Correct |
35 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
364 KB |
Output is correct |
17 |
Correct |
11 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
416 KB |
Output is correct |
19 |
Correct |
26 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
57 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
492 KB |
Output is correct |
14 |
Correct |
63 ms |
364 KB |
Output is correct |
15 |
Correct |
35 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
364 KB |
Output is correct |
17 |
Correct |
11 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
416 KB |
Output is correct |
19 |
Correct |
26 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Execution timed out |
1092 ms |
424 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
57 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
492 KB |
Output is correct |
14 |
Correct |
63 ms |
364 KB |
Output is correct |
15 |
Correct |
35 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
364 KB |
Output is correct |
17 |
Correct |
11 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
416 KB |
Output is correct |
19 |
Correct |
26 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Execution timed out |
1092 ms |
424 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
57 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
492 KB |
Output is correct |
14 |
Correct |
63 ms |
364 KB |
Output is correct |
15 |
Correct |
35 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
364 KB |
Output is correct |
17 |
Correct |
11 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
416 KB |
Output is correct |
19 |
Correct |
26 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Execution timed out |
1092 ms |
424 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
46 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
81 ms |
364 KB |
Output is correct |
9 |
Correct |
6 ms |
364 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
57 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
492 KB |
Output is correct |
14 |
Correct |
63 ms |
364 KB |
Output is correct |
15 |
Correct |
35 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
364 KB |
Output is correct |
17 |
Correct |
11 ms |
364 KB |
Output is correct |
18 |
Correct |
37 ms |
416 KB |
Output is correct |
19 |
Correct |
26 ms |
364 KB |
Output is correct |
20 |
Correct |
19 ms |
364 KB |
Output is correct |
21 |
Execution timed out |
1092 ms |
424 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |