Submission #180274

#TimeUsernameProblemLanguageResultExecution timeMemory
180274NightmarBootfall (IZhO17_bootfall)C++17
0 / 100
1035 ms476 KiB
#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; }
#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...