Submission #459598

#TimeUsernameProblemLanguageResultExecution timeMemory
459598JovanBBootfall (IZhO17_bootfall)C++17
65 / 100
1004 ms4388 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 500; const int ofs = N*N; const int MOD = 1000000007; int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; } int sub(int a, int b){ return add(a, MOD - b); } int moze[N*N+5]; int dp[2*N*N+5]; int a[N+5]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n; cin >> n; int poc = 0; for(int i=1; i<=n; i++){ cin >> a[i]; poc -= a[i]; a[i] *= 2; } dp[ofs + poc] = 1; for(int i=1; i<=n; i++){ for(int j=N*N; j>=-N*N+a[i]; j--){ dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]); } } if(dp[ofs] == 0){ cout << "0\n"; return 0; } for(int i=1; i<=n; i++){ for(int j=-N*N+a[i]; j<=N*N; j++){ dp[ofs + j] = sub(dp[ofs + j], dp[ofs + j - a[i]]); } for(int j=1; j<=N*N; j++) moze[j] += (dp[ofs + j - a[i]/2] > 0); for(int j=N*N; j>=-N*N+a[i]; j--){ dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]); } } vector <int> vec; for(int i=1; i<=N*N; i++) if(moze[i] == n) vec.push_back(i); cout << vec.size() << "\n"; for(auto c : vec) cout << c << " "; cout << "\n"; 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...