Submission #1241344

#TimeUsernameProblemLanguageResultExecution timeMemory
1241344sitingfakeBootfall (IZhO17_bootfall)C++20
100 / 100
424 ms31672 KiB
#include<bits/stdc++.h> using namespace std; // define #define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n"; #define ll long long #define ld double #define ii pair<int,int> #define se second #define fi first #define iii pair<int,ii> #define all(v) v.begin(),v.end() #define bit(x,i) (((x)>>(i))&1LL) #define flip(x,i) ((x)^(1LL<<(i))) #define ms(d,x) memset(d,x,sizeof(d)) #define sitingfake 1 #define orz 1 #define exist __exist #define ends __ends #define visit visited #define left __left #define right __right //constant const ll mod = 1e9 + 7; const long long linf = 4557430888798830399; const int inf = 1061109567; const int maxarr = 1e6 + 5; int dx[] = {0 , -1 , 0 , 1}; int dy[] = {-1 , 0 , 1 , 0}; template<typename T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } template<typename T> bool minimize(T &a, const T &b) { if(a > b) {a = b; return 1;} return 0; } inline void Plus(ll & a ,ll b) { b %= mod; a += b; if(a >= mod) a -= mod; if(a < 0) a += mod; return; } inline void Mul(ll & a, ll b) { a %= mod; b %= mod; a *= b; a %= mod; return; } //code const int maxn = 505; int a[maxn]; int n; int sum = 0; bitset <250001> dp , ans , pre[maxn] , suf[maxn]; void solve(void) { cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if(sum & 1) { cout << 0; return; } dp[0] = 1; for(int i = 1; i <= n; i++) { dp |= (dp << a[i]); } if(!dp[sum / 2]) { cout << 0; return; } pre[0][sum] = 1; for(int i = 1; i <= n; i++) { pre[i] = pre[i - 1] | (pre[i - 1] >> (2 * a[i])); } suf[n + 1][sum] = 1; for(int i = n; i >= 1; i--) { suf[i] = suf[i + 1] | (suf[i + 1] >> (2 * a[i])); } dp.reset(); ans.set(); for(int i = 1; i <= n; i++) { if(i > n / 2) { dp = pre[i - 1]; for(int j = i + 1; j <= n; j++) { dp |= (dp >> (2 * a[j])); } } else { dp = suf[i + 1]; for(int j = i - 1; j >= 1; j--) { dp |= (dp >> (2 * a[j])); } } dp >>= a[i]; ans &= dp; dp.reset(); } cout << ans.count() << "\n"; for(int i = 1; i <= 250000; i++) { if(ans[i]) { cout << i << " "; } } } /** 4 1 315 **/ signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tc; tc = 1; while(tc--) solve(); //execute; }

Compilation message (stderr)

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