Submission #670340

#TimeUsernameProblemLanguageResultExecution timeMemory
670340mychecksedadBootfall (IZhO17_bootfall)C++17
65 / 100
533 ms4692 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define pb push_back const int N = 510, M = 502, MX = 500*500 + 10; int n, a[N], S = 0; bitset<MX/2> dp[N]; void solve(){ cin >> n; bool ok = 1; for(int i = 1; i <= n; ++i){ cin >> a[i]; S += a[i]; if(a[i] % 2 != a[1] % 2){ ok = 0; } } if(!ok || S % 2){ cout << 0; return; } vector<int> used(M); vector<int> s; s.pb(0); for(int i = 1; i <= n; ++i){ if(!used[a[i]]) s.pb(i); used[a[i]] = 1; } for(int i: s){ dp[i][0] = 1; for(int l = 1; l <= n; ++l){ if(i == l) continue; dp[i] = dp[i] | (dp[i] << a[l]); } } vector<int> possible; for(int x = 2 - (a[1] % 2); x <= S; x += 2){ ok = 1; a[0] = x; for(int i: s){ bool state1 = 0, state2 = 0; int req = -1, req1 = -1; int c = S + x - a[i]; req = c >> 1; if(req <= S){ if(req > S/2) req = c - req; state1 = dp[i][req]; } if(i > 0){ req1 = (c >> 1) - x; if(req1 >= 0 && req1 <= S){ if(req1 > S/2) req1 = c - req1; state2 = dp[i][req1]; } } if(!(state1 | state2)){ ok = 0; break; } } if(ok){ possible.pb(x); } } cout << possible.size() << '\n'; for(int p: possible) cout << p << ' '; } int main(){ cin.tie(0); ios::sync_with_stdio(0); solve(); 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...