Submission #1128103

#TimeUsernameProblemLanguageResultExecution timeMemory
1128103BilAktauAlmansurBootfall (IZhO17_bootfall)C++17
100 / 100
602 ms2636 KiB
#include <bits/stdc++.h> #pragma optimize("g", on) // #pragma GCC optimize ("inline") // #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") void Freopen () { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } using namespace std; #define fi first #define se second // #define int long long const int N = 250000 + 7, M = 250000; short int n, a[507]; int us[N]; signed main() { // freopen("duty.in", "r", stdin); // freopen("duty.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); //Freopen(); cin>>n; for(short int i = 1; i <= n; i++) { cin>>a[i]; } sort(a + 1, a + 1 + n); int need = accumulate(a + 1, a + 1 + n, 0); for(int i = 1; i <= need; i++)us[i] = 1; if(need % 2 == 1) { cout << "0\n"; return 0 ; } need /= 2; bitset<M> st; st[0] = 1; for(int i = 1; i <= n; i++)st |= (st << a[i]); if(!st[need]) { cout << "0\n"; return 0; } st.reset(); need *= 2; st[0] = 1; for(int j = 1; j <= n; j++) { bitset<M> ts = st; for(int i = j + 1; i <= n; i++)ts |= (ts << a[i]); int s = 1; if(a[1] % 2 == 0)s ++; for(int i = s; i <= need; i += 2) { if(!us[i])continue; int W = need + i - a[j]; if(W % 2 == 1) { us[i] = 0; continue; } if(!ts[W / 2])us[i] = 0; } st |= (st << a[j]); } vector<int> ans; int s = 1; if(a[1] % 2 == 0)s ++; for(int i = s; i <= need; i += 2)if(us[i])ans.push_back(i); cout << ans.size() << '\n'; for(auto j : ans)cout << j << ' '; cout << '\n'; } /* please AC */

Compilation message (stderr)

bootfall.cpp: In function 'void Freopen()':
bootfall.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen("output.txt", "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...