Submission #505875

#TimeUsernameProblemLanguageResultExecution timeMemory
505875vonatlusBootfall (IZhO17_bootfall)C++17
0 / 100
2 ms404 KiB
/// adil sultanov | vonat1us #pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:36777216") #include<bits/stdc++.h> #define x first #define y second #define pb push_back #define sz(x) (int) x.size() #define all(z) (z).begin(), (z).end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1e9 + 1e2; void fin() { #ifdef AM freopen(".in", "r", stdin); #endif } const bool flag = 0; const int N = 1e5+10; void ma1n() { int n; cin >> n; vector<int> a(n); for (int& x : a) cin >> x; int sum = accumulate(all(a), 0); bitset<500*501> dp; dp.reset(); vector<int> ans; dp.set(0, 1); for (int j = 0; j < n; ++j) { dp |= dp<<a[j]; } if (sum&1 || !dp[sum/2]) cout << 0, exit(0); dp.reset(); dp.set(0, 1); for (int i = 1; i < n; ++i) { dp |= dp<<a[i]; } for (int j = 0; j <= sum/2; ++j) { if (dp[j] && j*2 != sum-a[0]) { ans.pb(abs(j - (sum-a[0]-j))); } } sort(all(ans)); ans.erase(unique(all(ans)), ans.end()); for (int i = 1; i < n; ++i) { dp.reset(); dp.set(0, 1); for (int j = 0; j < n; ++j) { if (i != j) { dp |= dp<<a[j]; } } for (int j = 0; j < sz(ans); ++j) { int s1 = (sum-a[i]-ans[j])/2; int s2 = sum-a[i]-s1; if (s1+s2 != sum-a[i] || min(s1, s2) < 0 || s1+ans[j] != s2 || !dp[s1] || !dp[s2]) { swap(ans[j], ans.back()); ans.pop_back(); j--; } } } cout << sz(ans) << "\n"; for (int x : ans) cout << x << " "; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr), fin(); int ts = 1; if (flag) { cin >> ts; } while (ts--) { ma1n(); } return 0; }
#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...