답안 #1058567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058567 2024-08-14T10:59:58 Z Nickpapadak Kpart (eJOI21_kpart) C++14
10 / 100
2000 ms 1016 KB
#include<bits/stdc++.h>
using namespace std;

int T;

void BruteForce(){
    while(T--){
        int N;
        scanf("%d", &N);
        int a[N+2], p[N+2];
        p[0] = 0;
        for(int i = 1; i<=N;++i){
            scanf("%d", &a[i]);
            p[i] = p[i-1] + a[i];
        }
        
        queue<int> ans;
        for(int k = 2; k<= N; ++k){
            bool ok = true;
            for(int i = 1; i+k-1 <= N;++i){
                int sm = (p[i+k-1]-p[i-1]);
                if(sm % 2 == 1){
                    ok = false;
                    break;
                }
                set<int> prev;
                prev.insert(0);
                set<int> next;
                for(int j = i; j<= i+k-1; ++j){
                    for(int num: prev){
                        next.insert(num+a[j]);
                    }
                    prev = next;
                }
                if(prev.count((sm>>1)) == 0){
                    ok = false;
                    break;
                }
                
            }
            if(ok) ans.push(k);
        }
        
        printf("%ld", ans.size());
        while(!(ans.empty())){
            printf(" %d", ans.front());ans.pop();
        }
        printf("\n");
    }
}

int main(){
    scanf("%d", &T);
    BruteForce();

    return 0;
}

Compilation message

Main.cpp: In function 'void BruteForce()':
Main.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
Main.cpp:13:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |             scanf("%d", &a[i]);
      |             ~~~~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 1016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 860 KB Time limit exceeded
2 Halted 0 ms 0 KB -