Submission #663557

#TimeUsernameProblemLanguageResultExecution timeMemory
663557Ninja_KunaiBootfall (IZhO17_bootfall)C++17
28 / 100
1089 ms716 KiB
/** * Author : Nguyen Tuan Vu * Created : 27.11.2022 **/ #pragma GCC optimize("O3") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define MASK(x) ((1)<<(x)) #define BIT(x, i) (((x)>>(i))&(1)) #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define db(val) "["#val" = "<<(val)<<"] " #define TIME (1.0 * clock() / CLOCKS_PER_SEC) template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Rand(int l, int r) {return l + rng() % (r - l + 1);} void file(){ #define TASK "TASK" if(fopen(TASK".in", "r")) { freopen(TASK".in", "r", stdin); freopen(TASK".out", "w", stdout); } } const int N = 5e2 + 5; const int M = 5e2 * 5e2; int n, a[N], b[N]; bitset <2 * M + 5> dp[2]; bitset <2 * M + 5> calc(int n) { dp[0].reset(); dp[1].reset(); dp[0][M] = 1; REP(i, n) { if (dp[i & 1].count() == 0) break; dp[(i + 1) & 1] |= dp[i & 1] << b[i + 1]; dp[(i + 1) & 1] |= dp[i & 1] >> b[i + 1]; dp[i & 1].reset(); } return dp[n & 1]; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); file(); cin >> n; FOR(i, 1, n) cin >> a[i], b[i] = a[i]; if (calc(n)[M] == 0) return cout << 0, 0; bitset <2 * M + 5> tmp; FOR(i, 0, 2 * M) tmp[i] = 1; vector <int> ID; FOR(i, 1, n) ID.push_back(i); if (n <= 200) { FOR(i, 1, n) { int cnt = 0; FOR(j, 1, n) if (i != j) b[++cnt] = a[j]; tmp &= calc(n - 1); if (tmp.count() == 0) break; } } else { FOR(t, 1, n / 4) { int i = ID[t - 1]; int cnt = 0; FOR(j, 1, n) if (i != j) b[++cnt] = a[j]; tmp &= calc(n - 1); if (tmp.count() == 0) break; } } vector <int> ans; FOR(i, 0, 2 * M) if (tmp[i]) ans.push_back(abs(i - M)); sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end()); cout << ans.size() << '\n'; for (auto x : ans) cout << x << ' '; cerr << "Time elapsed: " << TIME << " s.\n"; return 0; } /* ==================================================+ INPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ */

Compilation message (stderr)

bootfall.cpp: In function 'void file()':
bootfall.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(TASK".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         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...