답안 #366144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366144 2021-02-13T10:14:26 Z nicolaalexandra Bootfall (IZhO17_bootfall) C++14
0 / 100
4 ms 6252 KB
#include <bits/stdc++.h>
#define DIM 502
using namespace std;

bool dp_left[DIM][DIM*DIM],dp_right[DIM][DIM*DIM],dp[DIM];
int v[DIM],f[DIM*DIM];
vector <int> sol,w,w2;
int n,i,j,sum_total;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    for (i=1;i<=n;i++){
        cin>>v[i];
        sum_total += v[i];
    }

    if (sum_total % 2){
        cout<<"0";
        return 0;
    }

    dp[0] = 1;
    for (i=1;i<=n;i++){
        for (j=sum_total-v[i];j>=0;j--){
            if (dp[j])
                dp[j+v[i]] = 1;
        }
    }

    if (!dp[sum_total/2]){
        cout<<"0";
        return 0;
    }

    dp_left[0][0] = 1;
    for (i=1;i<=n;i++){
        memcpy (dp_left[i],dp_left[i-1],sizeof dp_left[i-1]);
        for (j=sum_total-v[i];j>=0;j--){
            if (dp_left[i][j])
                dp_left[i][j+v[i]] = 1;
        }
    }

    dp_right[n+1][0] = 1;
    for (i=n;i;i--){
        memcpy (dp_right[i],dp_right[i+1],sizeof dp_right[i+1]);
        for (j=sum_total-v[i];j>=0;j--){
            if (dp_right[i][j])
                dp_right[i][j+v[i]] = 1;
        }
    }


    for (i=1;i<=n;i++){

        w.clear(); w2.clear();
        for (int j=0;j<=sum_total;j++){
            if (dp_left[i-1][j])
                w.push_back(j);
            if (dp_right[i+1][j])
                w2.push_back(j);
        }

        memset (dp,0,sizeof dp);
        for (auto it : w)
            for (auto it2 : w2)
                dp[it+it2] = 1;

        int sum = sum_total - v[i];
        for (j=1;j<=sum_total;j++){
            if ( (sum + j)%2 )
                continue;

            int val = (sum + j)/2; /// exista suma asta?

            if (dp[val-j])
                f[j]++;

        }
    }

    for (i=1;i<=sum_total;i++){
        if (f[i] == n)
            sol.push_back(i);
    }

    cout<<sol.size()<<"\n";
    for (auto it : sol)
        cout<<it<<" ";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 4 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Incorrect 4 ms 6252 KB Output isn't correct
9 Halted 0 ms 0 KB -