Submission #1208731

#TimeUsernameProblemLanguageResultExecution timeMemory
1208731lopkusBootfall (IZhO17_bootfall)C++20
100 / 100
560 ms2872 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second #define all(v) (v).begin(),(v).end() #define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end()); const int N = 505; const int mod = 293847109; int n, a[N], dp[N * N], sum; int cnt[N * N], ans; void add(int x) { for (int s = sum; s >= x; s--) (dp[s] += dp[s - x]) %= mod; } void del(int x) { for (int s = x; s <= sum; s++) (dp[s] += mod - dp[s - x]) %= mod; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "task" if (fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } if (fopen("task.INP", "r")) { freopen("task.INP", "r", stdin); freopen("task.OUT", "w", stdout); } cin>>n; for (int i = 1; i <= n; i++) cin>>a[i], sum += a[i]; dp[0] = 1; for (int i = 1; i <= n; i++) add(a[i]); if (sum & 1 || !dp[sum / 2]) return cout<<0, 0; for (int i = 1; i <= n; i++) { del(a[i]); for (int s = 0; s <= sum - a[i]; s++) if (dp[s]) cnt[max(0, sum - a[i] - s - s)]++; add(a[i]); } for (int i = 1; i <= sum; i++) if (cnt[i] == n) ans++; cout<<ans<<'\n'; for (int i = 1; i <= sum; i++) if (cnt[i] == n) cout<<i<<' '; cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n"; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen("task.OUT", "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...