답안 #91234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91234 2018-12-26T15:40:10 Z Vardanyan Bootfall (IZhO17_bootfall) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 505;
bool dp[N][N*N*5]
int a[N];
int dp1[N*N*5];
int main()
{
    int n;
    scanf("%d",&n);
    int MX = 0;
    int sum = 0;
    for(int i = 1;i<=n;i++){
            scanf("%d",&a[i]);
            MX+=a[i];
            sum+=a[i];
    }
    sort(a+1,a+1+n);
        dp1[0] = 1;
        for(int j = 1;j<=n;j++){
            for(int s = 2*MX;s>=0;s--){
                if(dp1[s]) dp1[s+a[j]] += dp1[s];
            }
        }
    for(int i = 1;i<=n;i++){
        for(int s = 0;s<=2*MX;s++) dp1[s+a[i]] -= dp1[s];
        for(int s = 0;s<=2*MX;s++) dp[i][s] = dp1[s];
        for(int s = 2*MX;s>=0;s--) dp1[s+a[i]] += dp1[s];
    }
    if(!dp1[sum/2]){
        printf("0\n");
        return 0;
    }
    vector<int> ans;
    for(int x = 1;x<=MX;x++){
        sum+=x;
        bool F = true;
        for(int i = 1;i<=n;i++){
            sum-=a[i];
            int need = sum/2;
            sum+=a[i];
            if(need-x<0){
                F = false;
                break;
            }
            if(dp[i][need-x] && (sum-a[i])%2 == 0) continue;
            F = false;
            break;
        }
        sum-=x;
        if(F) ans.push_back(x);
    }
    printf("%d\n",ans.size());
    for(int i = 0;i<ans.size();i++) printf("%d ",ans[i]);
    printf("\n");
    return 0;
}

Compilation message

bootfall.cpp:6:1: error: expected initializer before 'int'
 int a[N];
 ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:15:25: error: 'a' was not declared in this scope
             scanf("%d",&a[i]);
                         ^
bootfall.cpp:19:10: error: 'a' was not declared in this scope
     sort(a+1,a+1+n);
          ^
bootfall.cpp:28:36: error: 'dp' was not declared in this scope
         for(int s = 0;s<=2*MX;s++) dp[i][s] = dp1[s];
                                    ^~
bootfall.cpp:28:36: note: suggested alternative: 'dp1'
         for(int s = 0;s<=2*MX;s++) dp[i][s] = dp1[s];
                                    ^~
                                    dp1
bootfall.cpp:47:16: error: 'dp' was not declared in this scope
             if(dp[i][need-x] && (sum-a[i])%2 == 0) continue;
                ^~
bootfall.cpp:47:16: note: suggested alternative: 'dp1'
             if(dp[i][need-x] && (sum-a[i])%2 == 0) continue;
                ^~
                dp1
bootfall.cpp:54:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
bootfall.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<ans.size();i++) printf("%d ",ans[i]);
                   ~^~~~~~~~~~~
bootfall.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~