이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair < int, int > pii;
typedef vector<int> vi;
typedef vector<long long> vll;
const int N = 250000 + 1;
const ll mod = 1e9 + 7;
void solve(){
int n;
cin >> n;
int a[n], x = 0;
bitset<N> can;
for(int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
}
map<int, bool> hv;
hv[0] = 1;
for(int j = 0; j < n; j++) {
vi ev;
for(auto o : hv) {
ev.pb(o.ff + a[j]);
}
for(auto o : ev)hv[o] = 1;
}
if(x % 2 || hv.find(x / 2) == hv.end()) {
cout << "0";
return;
}
for(int i = 1; i < N; i++) can[i] = 1;
for(int i = 0; i < n; i++) {
hv.clear();
x = 0;
hv[0] = 1;
for(int j = 0; j < n; j++) {
if(j == i)continue;
vi ev;
for(auto o : hv) {
ev.pb(o.ff + a[j]);
}
for(auto o : ev)hv[o] = 1;
x += a[j];
}
for(int p = can._Find_first(); p != can.size(); p = can._Find_next(p)) {
if((x + p) % 2)can[p] = 0;
else if(hv.find((x + p) / 2) == hv.end() && hv.find((x + p) / 2 - p) == hv.end()) can[p] = 0;
}
}
cout << can.count() << '\n';
for(int p = can._Find_first(); p != can.size(); p = can._Find_next(p)) {
cout << p << ' ';
}
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int times = 1;
//cin >> times;
while(times--)solve();
return 0;
}
# | 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... |