# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1128249 | _Temirhan | Bootfall (IZhO17_bootfall) | C++20 | 773 ms | 4084 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(x) x.size()
#define F first
#define S second
#define nl '\n'
void Tima()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 500 * 500 + 1;
const int inf = 1e12;
const int mod = 1e9 + 7;
signed main()
{
// Tima();
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >>n;
int a[n + 1], sum = 0;
for( int i = 1; i <= n; ++i )
{
cin >>a[i];
sum += a[i];
}
vector< int >dp(N, 0);
dp[0] = 1;
for( int i = 1; i <= n; ++i )
for( int w = N - 1; w >= a[i]; --w )
dp[w] = (dp[w] + dp[w - a[i]]) % mod;
if( (sum & 1) || !dp[sum / 2] )
{
cout <<0;
return 0;
}
vector< bool >ch(N, 1);
for( int i = 1; i <= n; ++i )
{
for( int w = a[i]; w < N; ++w )
dp[w] = (dp[w] - dp[w - a[i]] + mod) % mod;
for( int s = 1; s < N; ++s )
if( (sum - a[i] + s) % 2 == 1 || !dp[(sum - a[i] + s) / 2] )
ch[s] = false;
for( int w = N - 1; w >= a[i]; --w )
dp[w] = (dp[w] + dp[w - a[i]]) % mod;
}
vector< int >ans;
for( int i = 1; i < N; ++i )
if( ch[i] )
ans.pb( i );
cout <<sz(ans) <<nl;
for( int i: ans )
cout <<i <<' ';
}
컴파일 시 표준 에러 (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... |