답안 #92759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92759 2019-01-04T13:06:33 Z toloraia Bootfall (IZhO17_bootfall) C++14
13 / 100
8 ms 632 KB
#include <bits/stdc++.h>
#define ll long long int
#pragma GCC("O3")
using namespace std;

const int N = 505, M = 260010, P = 5;
const ll B = 9e18;

int n;
int a[N];
bool F[M], f;
int S;
ll DP[M][P];
ll dp[M][P];
int ans[M], ANS[M];
int V[M], np;
int main()
{
    cin>>n;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
        S += a[i];
    }
    sort (a + 1, a + n + 1);
    bool ok = 0;
    for (int i = 2; i <= n; i++)
        if ((a[i] - a[i - 1]) % 2 == 1)
            ok = 1;
    if (S % 2 == 1)
        ok = 1;
    if (ok){
        cout<<0<<endl;
        return 0;
    }
    F[0] = 1;
    DP[0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = S; j >= a[i]; j--)
            if (F[j - a[i]]){
                F[j] = 1;
                for (int l = 0; l < P; l++){
                    DP[j][l] += DP[j - a[i]][l];
                    if (DP[j][l] >= B){
                        DP[j][l + 1]++;
                        DP[j][l] -= B;
                    }
                }
            }
    }
    if (F[S / 2] == 0){
        cout<<0<<endl;
        return 0;
    }
    for (int i = 0; i <= S; i++)
        if (F[i])
            V[np++] = i;
    for (int I = 1; I <= n; ++I){
        for (int i1 = 0; i1 < np; ++i1){
            int i = V[i1];
            for (int j = 0; j < P; j++)
                dp[i][j] = DP[i][j];
            ans[abs (S - 2 * i - a[I])] = 0;
        }
        for (int i1 = 0; i1 < np; ++i1){
            int i = V[i1];
                f = 1;
                if (i >= a[I]){
                    f = 0;
                    for (int j = 0; j < P; ++j){
                        dp[i][j] -= dp[i - a[I]][j];
                        if (dp[i][j] < 0){
                            dp[i][j] += B;
                            dp[i][j + 1]--;
                        }
                        if (dp[i][j])
                            f = 1;
                    }
                }
                if (f && ans[abs (S - a[I] - 2 * i)] == 0){
                    ans[abs (S - a[I] - 2 * i)] = 1;
                    ANS[abs (S - a[I] - 2 * i)]++;
                }
            }
    }
    np = 0;
    for (int i = 1; i <= S; i++)
        if (ANS[i] == n)
            V[np++] = i;
    cout<<np<<endl;
    for (int i = 0; i < np; i++)
        cout<<V[i]<<" ";
    cout<<endl;
    return 0;
}

Compilation message

bootfall.cpp:3:0: warning: ignoring #pragma GCC  [-Wunknown-pragmas]
 #pragma GCC("O3")
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Incorrect 8 ms 632 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Incorrect 8 ms 632 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Incorrect 8 ms 632 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Incorrect 8 ms 632 KB Output isn't correct
23 Halted 0 ms 0 KB -