Submission #727934

#TimeUsernameProblemLanguageResultExecution timeMemory
727934dxz05Bootfall (IZhO17_bootfall)C++17
100 / 100
676 ms2980 KiB
//#pragma GCC optimize("Ofast,O3,unroll-loops") //#pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define MP make_pair //#define endl '\n' mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long long ll; const int MOD = 1e9 + 7; const int N = 502; const int M = N * N; int a[N]; void solve(){ int n; cin >> n; vector<int> dp(M, 0); dp[0] = 1; for (int i = 1; i <= n; i++){ cin >> a[i]; for (int x = M - 1; x >= a[i]; x--){ dp[x] += dp[x - a[i]]; if (dp[x] >= MOD) dp[x] -= MOD; } } int sum = accumulate(a + 1, a + n + 1, 0); if (sum % 2 == 1 || dp[sum / 2] == 0){ cout << 0 << endl; return; } vector<int> cnt(M, 0); for (int i = 1; i <= n; i++){ for (int x = a[i]; x < M; x++){ dp[x] -= dp[x - a[i]]; if (dp[x] < 0) dp[x] += MOD; } for (int t = 1; t < M; t++){ int s = sum - a[i] + t; if (s % 2) continue; s /= 2; if (dp[s] || s >= t && dp[s - t]) cnt[t]++; } for (int x = M - 1; x >= a[i]; x--){ dp[x] += dp[x - a[i]]; if (dp[x] >= MOD) dp[x] -= MOD; } } int ans = count(all(cnt), n); cout << ans << endl; for (int i = 1; i < M; i++){ if (cnt[i] == n){ cout << i << ' '; } } cout << endl; } int main(){ clock_t startTime = clock(); ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test_cases = 1; // cin >> test_cases; for (int test = 1; test <= test_cases; test++){ // cout << (solve() ? "YES" : "NO") << endl; solve(); } cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl; return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'void solve()':
bootfall.cpp:60:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   60 |             if (dp[s] || s >= t && dp[s - t]) cnt[t]++;
#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...