Submission #92756

#TimeUsernameProblemLanguageResultExecution timeMemory
92756toloraiaBootfall (IZhO17_bootfall)C++14
44 / 100
1080 ms18680 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 505, M = 260010, P = 7; const ll B = 1e18; int n; int a[N]; bool F[M], f; int S; ll DP[M][10]; ll dp[M][10]; int ans[M], ANS[M]; int V[M], np; int main() { cin>>n; for (int i = 1; i <= n; i++){ cin>>a[i]; S += a[i]; } sort (a + 1, a + n + 1); bool ok = 0; for (int i = 2; i <= n; i++) if ((a[i] - a[i - 1]) % 2 == 1) ok = 1; if (S % 2 == 1) ok = 1; if (ok){ cout<<0<<endl; return 0; } F[0] = 1; DP[0][0] = 1; for (int i = 1; i <= n; i++){ for (int j = S; j >= a[i]; j--) if (F[j - a[i]]){ F[j] = 1; for (int l = 0; l < P; l++){ DP[j][l] += DP[j - a[i]][l]; if (DP[j][l] >= B){ DP[j][l + 1]++; DP[j][l] -= B; } } } } if (F[S / 2] == 0){ cout<<0<<endl; return 0; } for (int i = 0; i <= S; i++) if (F[i]) V[np++] = i; for (int I = 1; I <= n; ++I){ for (int i1 = 0; i1 < np; ++i1){ int i = V[i1]; for (int j = 0; j < P; j++) dp[i][j] = DP[i][j]; ans[abs (S - 2 * i - a[I])] = 0; } for (int i1 = 0; i1 < np; ++i1){ int i = V[i1]; f = 1; if (i >= a[I]){ f = 0; for (int j = 0; j < P; ++j){ dp[i][j] -= dp[i - a[I]][j]; if (dp[i][j] < 0){ dp[i][j] += B; dp[i][j + 1]--; } if (dp[i][j]) f = 1; } } if (f && ans[abs (S - a[I] - 2 * i)] == 0){ ans[abs (S - a[I] - 2 * i)] = 1; ANS[abs (S - a[I] - 2 * i)]++; } } } np = 0; for (int i = 1; i <= S; i++) if (ANS[i] == n) V[np++] = i; cout<<np<<endl; for (int i = 0; i < np; i++) cout<<V[i]<<" "; cout<<endl; 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...