Submission #536195

#TimeUsernameProblemLanguageResultExecution timeMemory
536195akhan42Bootfall (IZhO17_bootfall)C++17
44 / 100
1022 ms2640 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define F first #define S second #define forn(i, n) for(int i = 0; i < n; ++i) #define forbn(i, b, n) for(int i = b; i < n; ++i) #define sz(v) (int)v.size() #define pb push_back #define mp make_pair #define eb emplace_back #define all(v) v.begin(), v.end() #define min3(a, b, c) min(a, min(b, c)) #define lc v << 1 #define rc (v << 1) + 1 typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long long ll; typedef complex<double> cd; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; template <class T> inline void mineq(T &a, T b) { a = min(a, b); } template <class T> inline void maxeq(T &a, T b) { a = max(a, b); } const int BASE = 500; const int MX = BASE * BASE + 1; using bts = bitset<MX>; int last_bit(bts& a) { int i = a._Find_first(); while(a._Find_next(i) != sz(a)) i = a._Find_next(i); return i; } int pr2 = 479001599; int add(int a, int b, int mod) { return ((a + b) % mod + mod) % mod; } bts divide(vi pol2, int d) { bts res; for(int i = 0; i + d < MX; i++) { if(pol2[i] != 0) { pol2[i + d] = add(pol2[i + d], -pol2[i], pr2); res[i] = 1; } } return res; } void solve() { int n; cin >> n; vi arr(n); forn(i, n) cin >> arr[i]; sort(all(arr)); vi pol2(MX, 0); pol2[0] = 1; for(int a: arr) { for(int i = MX - a - 1; i >= 0; i--) { pol2[i + a] = add(pol2[i + a], pol2[i], pr2); } } bts s; s[0] = 1; int total = 0; bool odd = true, even = true; for(int a: arr) { s |= s << a; total += a; if(a % 2) even = false; else odd = false; } if(total % 2 || s[total / 2] == 0 || (!even && !odd)) { cout << 0; return; } bts ans; ans.flip(); forn(i, n) { bts c = divide(pol2, arr[i]); int d = (total - arr[i] - (odd ? 1 : 0)) / 2; ans &= c >> d; } vi vans; forbn(i, 1, MX) { if(ans[i]) { vans.pb(2 * i - (odd ? 1 : 0)); } } cout << sz(vans) << '\n'; for(int el: vans) cout << el << ' '; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("triangles.in", "r", stdin); // freopen("triangles.out", "w", stdout); int t = 1; // cin >> t; while(t--) { solve(); } }

Compilation message (stderr)

bootfall.cpp: In function 'int last_bit(bts&)':
bootfall.cpp:40:24: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |  while(a._Find_next(i) != sz(a))
      |                        ^
#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...