제출 #170132

#제출 시각아이디문제언어결과실행 시간메모리
170132nvmdavaBootfall (IZhO17_bootfall)C++17
100 / 100
480 ms17392 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define INF 0x3f3f3f3f #define MOD 1000000007 #define N 1000005 bitset<501> in[250001]; bitset<250001> can; int a[505]; int cnt[505]; int ans[250005]; vector<int> v; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, s = 0; cin>>n; for(int i = 1; i <= n; ++i){ cin>>a[i]; cnt[a[i]]++; s += a[i]; } can[0] = 1; for(int i = 1; i <= 500; ++i){ for(int j = 1; j < cnt[i]; ++j){ can |= can << i; } } for(int i = 1; i <= 500; ++i){ if(!cnt[i]) continue; for(int j = s - i; j >= 0; --j){ if(can[j]){ bitset<501> t = in[j]; t[i] = 1; if(!can[j + i]){ in[j + i] = t; can[j + i] = 1; } else { in[j + i] &= t; } } } } if((s & 1) || !can[s / 2]){ cout<<0; return 0; } for(int i = 1; i <= 500; ++i){ if(cnt[i]){ for(int j = 1; j <= s; ++j){ if(can[j] && in[j][i] == 0){ int q = j * 2 + i - s; if(q <= 0) continue; ans[q] += cnt[i]; } } } } for(int i = 1; i <= 250000; i++){ if(ans[i] == n){ v.push_back(i); } } cout<<v.size()<<'\n'; for(auto& x : v) cout<<x<<' '; }
#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...