Submission #519782

#TimeUsernameProblemLanguageResultExecution timeMemory
519782Dasha_GnedkoBootfall (IZhO17_bootfall)C++17
100 / 100
488 ms3776 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/detail/standard_policies.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx2") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") using namespace std; //using namespace __gnu_pbds; //template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>; mt19937 gen(time(0)); #define ll long long #define ld long double #define pb push_back #define F first #define S second #define TIME clock() * 1.0 / CLOCKS_PER_SEC #define sz(a) int32_t(a.size()) #define endl '\n' //#define int long long const int N = 250100; const int M = 31; const int mod = 1e9 + 7; const ll inf = 1e18 + 7; int dp[N], ans[N], a[510]; bool cnt[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // LOCAL int n; cin >> n; int sum = 0; for(int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for(int i = 0; i < n; i++) { for(int j = N - 1; j >= a[i]; j--) dp[j] += dp[j - a[i]]; } if (sum % 2 || !dp[sum / 2]) { cout << 0; return 0; } for(int i = 0; i < n; i++) { for(int j = a[i]; j < N; j++) dp[j] -= dp[j - a[i]]; for(int j = N - 1; j >= 0; j--) { if (!dp[j]) continue; int x = j, y = sum - j - a[i]; cnt[abs(x - y)] = 1; } for(int i = 0; i < N; i++) { if (cnt[i]) ans[i]++; cnt[i] = 0; } for(int j = N - 1; j >= a[i]; j--) dp[j] += dp[j - a[i]]; } vector < int > ot; for(int i = 1; i < N; i++) if (ans[i] == n) ot.pb(i); cout << sz(ot) << endl; for(auto to: ot) cout << to << " "; }
#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...