Submission #337945

#TimeUsernameProblemLanguageResultExecution timeMemory
337945kutbilim_oneBootfall (IZhO17_bootfall)C++14
100 / 100
379 ms5992 KiB
/** kutbilim.one **/ #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(),x.end() #define int long long #define endl '\n' /* ifstream in("test.txt"); #define cin in */ const int MAX = 500*500+1; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); vector<int> dp(MAX, 0); vector<int> used(MAX, 1); dp[0] = 1; int sum = 0; for(int i = 0; i < n; i++){ cin >> a[i]; for(int x = sum; x >= 0; x--) dp[x+a[i]] += dp[x]; sum += a[i]; } if(sum%2 == 1 || dp[sum/2] == 0) return cout << 0, 0; for(int ex = 0; ex < n; ex++){ int left = sum-a[ex]; for(int x = 0; x <= left; x++) dp[x + a[ex]] -= dp[x]; for(int right = 0; right <= MAX; right++) if((left+right)%2 == 1 || dp[(left+right)/2] == 0) used[right] = 0; for(int x = left; x >= 0; x--) dp[x + a[ex]] += dp[x]; } vector<int> res; for(int i = 0; i <= MAX; i++){ if(used[i]) res.push_back(i); } cout << res.size() << endl; for(auto i : res) cout << i << " "; return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:41:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |         for(int right = 0; right <= MAX; right++)
      |         ^~~
bootfall.cpp:44:6: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |      for(int x = left; x >= 0; 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...