# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
682443 | iskhakkutbilim | Bootfall (IZhO17_bootfall) | C++14 | 1098 ms | 15272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 500;
const int S =2*500 * 500;
int dp[S+1];
main(){
int n; cin >> n;
vector<int> a(n);
int sum = 0, even = 0, odd = 0;
for(int i = 0;i < n; i++){
cin >> a[i];
odd+= (a[i]%2==1);
even+= (a[i]%2==0);
sum+= a[i];
}
dp[0] = 1;
for(int i = 0;i < n; i++){
for(int s = sum/2; s >= 0; s--){
if(s >= a[i]){
dp[s] = max(dp[s], dp[s-a[i]]);
}
}
}
if((even > 0 and odd > 0) or sum%2 or !dp[sum/2]){
cout << 0;
return 0;
}
set<int> can;
for(int tima = 1; tima <= S; tima++){
sum+= tima;
int ok = 1;
for(int i = 0;i < a.size(); i++){
if((sum-a[i])%2==1){
ok = 0;
break;
}
}
if(ok) can.insert(tima);
sum-= tima;
}
for(int i = 0;i < n; i++){
for(int s = sum; s >= 1; s--) dp[s] = 0;
for(int j = 0;j < n; j++){
if(i == j) continue;
for(int s = S; s >= 0; s--){
if(s>=a[j]) dp[s] = max(dp[s], dp[s-a[j]]);
}
}
vector<int> del;
for(int tima : can){
if(!dp[(sum-a[i]+tima) / 2]) del.push_back(tima);
}
for(int x : del) can.erase(x);
}
cout << can.size() << '\n';
for(int x : can) cout << x << ' ';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |