이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 3e5 + 5;
int t,n,a[N],dp[N], ans[N], sum;
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
vector <int> res;
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>a[i]; sum += a[i];
}
sort(a + 1, a + n + 1);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = sum; j >= a[i]; j--) {
dp[j] += dp[j - a[i]];
}
}
if (!sum % 2 || !dp[sum / 2]) {
cout<<0<<"\n"; exit(0);
}
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= sum; j++) {
dp[j] -= dp[j - a[i]];
}
sum -= a[i];
for (int j = 0; j <= sum; j++) {
if (dp[j] && sum - 2 * j >= 0) {
ans[sum - 2 * j]++;
if (ans[sum - 2 * j] == n) res.pb(sum - 2 * j);
}
}
sum += a[i];
for (int j = sum; j >= a[i]; j--) {
dp[j] += dp[j - a[i]];
}
}
cout<<res.size()<<"\n";
sort(res.begin(),res.end());
for (int x : res) {
cout<<x<<" ";
}
cout<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
bootfall.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main() {
| ^~~~
# | 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... |