Submission #1156677

#TimeUsernameProblemLanguageResultExecution timeMemory
1156677jahongirBootfall (IZhO17_bootfall)C++20
28 / 100
1093 ms1608 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define f first #define s second #define pb push_back #define all(a) (a).begin(),(a).end() void setIO(string name = ""){ ios_base::sync_with_stdio(false); cin.tie(nullptr); if(name.empty()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); }else{ freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } void solve(){ int n; cin >> n; vector<int> a(n); for(auto &x : a) cin >> x; sort(all(a)); int sum = 0; for(auto x : a) sum += x; if(sum%2){ cout << 0; return; } vector<int> dp(sum+500*n,0); dp[0] = 1; for(auto x : a){ for(int i = sum/2; i-x>=0; i--) dp[i] |= dp[i-x]; } if(!dp[sum/2]){ cout << 0; return; } map<int,int> mp; for(int i = 0; i < n; i++){ fill(all(dp),0); dp[0] = 1; sum -= a[i]; for(int j = 0; j < n; j++){ if(i==j) continue; for(int s = sum; s-a[j] >= 0; s--) dp[s] |= dp[s-a[j]]; } for(int j = 1; j <= sum; j++){ int temp = sum+j; if(temp&1) continue; if(dp[temp/2-j]) mp[j]++; } sum += a[i]; } set<int> ans; for(auto [f,s] : mp){ if(s==n) ans.insert(f); } cout << ans.size() << '\n'; for(auto x : ans) cout << x << ' '; } int main(){ int t=1; // cin >> t; while(t--) solve(); }

Compilation message (stderr)

bootfall.cpp: In function 'void setIO(std::string)':
bootfall.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         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...