제출 #1367439

#제출 시각아이디문제언어결과실행 시간메모리
1367439jbn8Bootfall (IZhO17_bootfall)C++20
44 / 100
1095 ms992 KiB
#include <cstdio>
#include <array>
#include <cassert>
using namespace std;

const int maxN = 350;
const int maxA = 351;
int main(){
    int N;
    scanf("%d\n", &N);
    array<int, maxN+1> a{};
    int sum = 0;
    for(int i=0; i<N; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    array<int, maxA*maxN> poss{};
    array<bool, maxN*maxA/2> cache{};
    cache[0] = true;
    for(int i=0; i<N+1; i++){
        int part = sum-a[i];
        if(i){
            int idp = i-1;
            for(int j=sum/2; j >= 0; j--){
                if(cache[j]){
                    cache[j+a[idp]] = true;
                }
            }
        }
        array<bool, maxN*maxA/2> possreferee = cache;
        for(int idp=i+1; idp<N; idp++){
            for(int j=part/2-a[idp]; j >= 0; j--){
                if(possreferee[j]){
                    possreferee[j+a[idp]] = true;
                }
            }
        }
        if(i == N && !possreferee[part/2]){
            printf("0\n");
            return 0;
        }
        if(i == N)continue;
        for(int idw=0; idw<=part/2; idw++){
            if(possreferee[idw]){
                poss[part-idw*2]++;
            }
        }
    }
    int count = 0;
    for(int i=0; i<sum; i++)
        count += poss[i] == N;
    printf("%d\n", count);
    if(count){
        for(int i=0; i<sum; i++){
            if(poss[i] == N){
                printf("%d ", i);
            }
        }
        printf("\n");
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bootfall.cpp: In function 'int main()':
bootfall.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d\n", &N);
      |     ~~~~~^~~~~~~~~~~~
bootfall.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…