Submission #673572

#TimeUsernameProblemLanguageResultExecution timeMemory
673572smartmonkyBootfall (IZhO17_bootfall)C++14
13 / 100
3 ms468 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} const int N = 5e3 + 1; int dp[N]; int used[N]; int main() { int n, sum = 0; cin >> n; vector <int> v(n); for(int i = 0; i < n; i++){ cin >> v[i]; sum += v[i]; } if(sum & 1){ cout << 0; return 0; } dp[0] = 1; for(int i = 0; i < n; i++){ for(int j = sum; j >= v[i]; j--){ dp[j] += dp[j - v[i]]; } } if(!dp[sum / 2]){ cout << 0; return 0; } vector <int> ans; for(int i = 0; i < n; i++){ int k = sum - v[i]; for(int j = v[i]; j <= sum; j++){ dp[j] -= dp[j - v[i]]; } for (int j = 0; j <= k / 2; j++) { if (dp[j]) used[k - j * 2]++; } for(int j = sum ; j >= v[i]; j--){ dp[j] += dp[j - v[i]]; } } for (int i = 0; i <= sum; i++) { if (used[i] == n) ans.pb(i); } cout << ans.size() << endl; for(auto x : ans) cout << x <<" "; }

Compilation message (stderr)

bootfall.cpp: In function 'void fp(std::string)':
bootfall.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...