Submission #93833

#TimeUsernameProblemLanguageResultExecution timeMemory
93833dalgerokBootfall (IZhO17_bootfall)C++14
100 / 100
359 ms4204 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 505, M = 1e7 + 5, MOD = 1e9 + 9; int n, a[N], sum, ssum; bool used[M]; long long dp[M]; inline void Add(int val){ sum += val; for(int i = sum; i >= 0; i--){ dp[i + val] += dp[i]; } } inline void Del(int val){ for(int i = 0; i <= sum; i++){ dp[i + val] -= dp[i]; } sum -= val; } main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; dp[0] = 1; for(int i = 1; i <= n; i++){ cin >> a[i]; ssum += a[i]; Add(a[i]); } for(int i = 1; i <= ssum; i++){ used[i] = true; } if(ssum % 2 || dp[ssum / 2] == 0){ return cout << 0, 0; } for(int i = 1; i <= n; i++){ Del(a[i]); for(int j = 1; j <= ssum; j++){ if((sum + j) % 2 || dp[(sum + j) / 2] == 0){ used[j] = false; } } Add(a[i]); } vector < int > ans; for(int i = 1; i <= ssum; i++){ if(used[i]){ ans.push_back(i); } } cout << (int)ans.size() << "\n"; for(auto it : ans){ cout << it << " "; } }

Compilation message (stderr)

bootfall.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#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...