이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 5e2 + 1, maxm = 3e5 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
ll n, sum;
unsigned ll a[maxn], dp[maxm], cnt[maxm], ans[maxm];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for(int j = maxm - 1; j >= a[i]; j--)
dp[j] += dp[j - a[i]];
sum += a[i];
}
if (sum % 2 != 0 || dp[sum / 2] == 0){
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i){
for (int j = a[i]; j <= maxm - 1; ++j){
dp[j] -= dp[j - a[i]];
}
for (int j = 0; j <= maxm - 1; ++j){
if (dp[j] > 0){
int f = j, s = sum - a[i] - j;
int rz = abs(f - s);
cnt[rz] = 1;
}
}
for (int j = 0; j <= maxm - 1; ++j){
if (cnt[j] > 0){
ans[j]++;
}
cnt[j] = 0;
}
for (int j = maxm - 1; j >= a[i]; --j){
dp[j] += dp[j - a[i]];
}
}
vector<int> v;
for (int i = 1; i <= maxm - 1; ++i){
if (ans[i] == n){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
컴파일 시 표준 에러 (stderr) 메시지
bootfall.cpp: In function 'int main()':
bootfall.cpp:25:33: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
25 | for(int j = maxm - 1; j >= a[i]; j--)
| ~~^~~~~~~
bootfall.cpp:50:34: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
50 | for (int j = maxm - 1; j >= a[i]; --j){
| ~~^~~~~~~
bootfall.cpp:56:20: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
56 | if (ans[i] == n){
| ~~~~~~~^~~~
# | 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... |