Submission #855108

#TimeUsernameProblemLanguageResultExecution timeMemory
855108AlfraganusBootfall (IZhO17_bootfall)C++17
28 / 100
1064 ms61276 KiB
#include <bits/stdc++.h> using namespace std; #define fs first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define print(a) \ for(auto x : a) \ cout << x << ' '; \ cout << endl; #define printmp(a) \ for (auto x : a) \ cout << x.fs << ' ' << x.ss << endl; vector<vector<int>> dp; void solve(){ int n; cin >> n; vector<int> a(n); int sum = 0; bool even = false, odd = false; for(int i = 0; i < n; i ++) cin >> a[i], sum += a[i], even |= !(a[i] & 1), odd |= (a[i] & 1); sort(all(a)); if((sum & 1)){ cout << 0; return; } if(even and odd){ cout << 0; return; } queue<int> q; q.push(sum / 2); bool flag = false; vector<bool> used(sum / 2); while(!q.empty()){ int x = q.front(); q.pop(); if(x == 0) flag = 1; if(!flag){ for(int i = 0; i < n; i ++){ if(x >= a[i] and !used[x - a[i]]){ used[x - a[i]] = 1; q.push(x - a[i]); } } } } if(!flag){ cout << 0; return; } dp.resize(n, vector<int> (sum)); for(int i = 0; i < n; i ++){ dp[i][0] = 1; vector<int> b; for(int j = 0; j < n; j ++){ if(i != j){ dp[i][a[j]] = 1; for (auto x : b) { if (x + a[j] < (int)dp[0].size() and dp[i][x + a[j]] == 0) { dp[i][x + a[j]] = 1; b.push_back(x + a[j]); } } b.push_back(a[j]); } } b.clear(); } if(even){ vector<int> ans; for(int j = 2; j <= sum - a[0]; j += 2){ int c = sum; for(int i = 0; i < n; i ++){ sum -= a[i]; sum += j; if(!((sum / 2 < (int)dp[0].size() and sum / 2 >= 0 and dp[i][sum / 2] == 1) or (sum / 2 - j < (int)dp[0].size() and sum / 2 >= j and dp[i][sum / 2 - j] == 1))) break; sum -= j; sum += a[i]; if(i == n - 1) ans.push_back(j); } sum = c; } cout << ans.size() << endl; print(ans) } else{ vector<int> ans; for (int j = 1; j <= sum - a[0]; j += 2) { int c = sum; for (int i = 0; i < n; i++) { sum -= a[i]; sum += j; if (!((sum / 2 < dp[0].size() and sum / 2 >= 0 and dp[i][sum / 2]) or (sum / 2 - j < dp[0].size() and sum / 2 >= j and dp[i][sum / 2 - j]))) break; sum -= j; sum += a[i]; if (i == n - 1) ans.push_back(j); } sum = c; } cout << ans.size() << endl; print(ans) } } signed main(){ // ios::sync_with_stdio(0); // cin.tie(0); int t = 1; // cin >> t; while(t --){ solve(); cout << endl; } }

Compilation message (stderr)

bootfall.cpp: In function 'void solve()':
bootfall.cpp:109:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 if (!((sum / 2 < dp[0].size() and sum / 2 >= 0 and dp[i][sum / 2]) or (sum / 2 - j < dp[0].size() and sum / 2 >= j and dp[i][sum / 2 - j])))
      |                        ~~~~~~~~^~~~~~~~~~~~~~
bootfall.cpp:109:100: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 if (!((sum / 2 < dp[0].size() and sum / 2 >= 0 and dp[i][sum / 2]) or (sum / 2 - j < dp[0].size() and sum / 2 >= j and dp[i][sum / 2 - j])))
      |                                                                                        ~~~~~~~~~~~~^~~~~~~~~~~~~~
#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...