# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1156677 | jahongir | Bootfall (IZhO17_bootfall) | C++20 | 1093 ms | 1608 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define all(a) (a).begin(),(a).end()
void setIO(string name = ""){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(name.empty()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}else{
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
void solve(){
int n;
cin >> n;
vector<int> a(n);
for(auto &x : a) cin >> x;
sort(all(a));
int sum = 0;
for(auto x : a) sum += x;
if(sum%2){
cout << 0;
return;
}
vector<int> dp(sum+500*n,0);
dp[0] = 1;
for(auto x : a){
for(int i = sum/2; i-x>=0; i--)
dp[i] |= dp[i-x];
}
if(!dp[sum/2]){
cout << 0;
return;
}
map<int,int> mp;
for(int i = 0; i < n; i++){
fill(all(dp),0);
dp[0] = 1;
sum -= a[i];
for(int j = 0; j < n; j++){
if(i==j) continue;
for(int s = sum; s-a[j] >= 0; s--)
dp[s] |= dp[s-a[j]];
}
for(int j = 1; j <= sum; j++){
int temp = sum+j;
if(temp&1) continue;
if(dp[temp/2-j]) mp[j]++;
}
sum += a[i];
}
set<int> ans;
for(auto [f,s] : mp){
if(s==n) ans.insert(f);
}
cout << ans.size() << '\n';
for(auto x : ans) cout << x << ' ';
}
int main(){
int t=1;
// cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (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... |