Submission #661099

#TimeUsernameProblemLanguageResultExecution timeMemory
661099Kaztaev_AlisherBootfall (IZhO17_bootfall)C++17
100 / 100
568 ms3448 KiB
//#pragma GCC optomize ("Ofast") //#pragma GCC optomize ("unroll-loops") //#pragma GCC target ("avx,avx2,fma") #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define sz size #define cl clear #define ins insert #define ers erase #define pii pair < int , int > #define pll pair< long long , long long > #define all(x) x.begin() , x.end() #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define tostr(x) to_string(x) #define tonum(s) atoi(s.c_str()) #define seon(x) setprecision(x) #define bpop(x) __builtin_popcount(x) #define deb(x) cerr << #x << " = " << x << endl; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; const double PI = 3.14159265; const ll N = 500+9 , M = 258000; const ll mod = 1e9+7; const ll inf = 1e9; const ll INF = 1e18; using namespace std; int dp[M]; int a[N]; vector<int> ans; int cnt[M]; void solve(){ int n; cin >> n; ll sum = 0; for(int i = 1; i <= n ; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for(int i = 1; i <= n ; i++) { for(int j = sum; j >= a[i]; j--) dp[j] += dp[j-a[i]]; } if(sum % 2 == 1 || dp[(sum>>1)] == 0){ cout << 0; return; } for(int i = 1; i <= n; i++){ for(int j = a[i]; j <= sum; j++) dp[j] -= dp[j-a[i]]; for(int x = 1; x <= sum-a[i]; x++){ int ob = sum-a[i]+x; if(ob % 2 == 0 && dp[ob/2-x]){ cnt[x]++; if(cnt[x] == n) ans.pb(x); } } for(int j = sum; j >= a[i]; j--) dp[j] += dp[j-a[i]]; } cout << ans.sz() <<"\n"; for(int x : ans) cout << x <<" "; } signed main(){ ios; 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...