Submission #1302503

#TimeUsernameProblemLanguageResultExecution timeMemory
1302503wuan281Bootfall (IZhO17_bootfall)C++20
65 / 100
1096 ms8624 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int mq = 500 * 500 + 5; const int mod = 1e18; int n; int dem[mq]; int lef[mq]; int a[mq]; int tong; int cntmp[mq]; int lev[mq]; int chose[mq]; void add(int x, int y){ dem[x] += dem[y]; lef[x] += lef[y]; if(lef[x] > mod){ dem[x]++; lef[x] = lef[x] - mod; } } void tru(int x, int y){ if(lef[x] >= lef[y]){ dem[x] -= dem[y]; lef[x] -= lef[y]; } else{ dem[x]--; dem[x] -= dem[y]; lef[x] = lef[x] + mod - lef[y]; } } signed main(){ cin.tie(nullptr)->sync_with_stdio(0); if(fopen("txt.inp", "r")){ freopen("txt.inp","r",stdin); freopen("txt.out","w",stdout); } cin >> n; lef[0] = 1; for(int i=1;i<=n;i++){ cin >> a[i]; tong += a[i]; } if(tong % 2 == 1){ cout << 0; return 0; } for(int i=1;i<=n;i++){ for(int j=tong;j>=a[i];j--){ add(j, j - a[i]); } } for(int i=0;i<=tong;i++){ cntmp[i] = dem[i]; lev[i] = lef[i]; } if(dem[tong / 2] == 0 and lef[tong / 2] == 0){ cout << 0; return 0; } for(int i=1;i<=tong;i++) chose[i] = 1; for(int i=1;i<=n;i++){ int sum = tong - a[i]; for(int j=0;j<=tong;j++){ dem[j] = cntmp[j]; lef[j] = lev[j]; } for(int j=a[i];j<=tong;j++){ tru(j, j - a[i]); } for(int j=0;j<=tong;j++){ if(chose[j] == 0) continue; int temp = sum + j; if(temp % 2 == 1){ chose[j] = 0; continue; } if(dem[temp / 2] == 0 and lef[temp / 2] == 0) chose[j] = 0; } } int ans = 0; for(int i=1;i<=tong;i++) ans += chose[i]; cout << ans << '\n'; for(int i=1;i<=tong;i++){ if(chose[i]) cout << i << ' '; } return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("txt.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen("txt.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...