답안 #1107742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107742 2024-11-02T04:32:08 Z vjudge1 Kpart (eJOI21_kpart) C++17
100 / 100
1093 ms 1344 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nn "\n";
#define pb push_back
#define all(v) (v).begin() , (v).end()
const int N = 1e5+ 4;
int dp[N] , bad[N];
int n , T , q , m ;
signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0);
    cin>> T;
    while(T--){
        cin>> n ;
        int a[n+1] , p[n+1];
        p[0] =0 ;
        for(int i=1 ; i <= n  ; i++){
            cin>>a[i];
            bad[i] =0 ;
            p[i] = p[i-1]+a[i];
        }
        for(int i= 1 ; i <= n ;i++){
            for(int j = N; j >= a[i]  ; j--){
                dp[j] = max(dp[j] , dp[j- a[i]]);
            }
            dp[a[i]] = i;
            for(int k = 1 ; k <= i; k++){
                int sum = p[i] - p[i-k];
                if(sum % 2 == 1 || dp[sum/2] <i - k + 1)bad[k] = 1 ;
            }
        }
        vector<int>w;
        for(int i=1 ; i <= n ; i++){
            if(!bad[i])w.pb(i);
        }
        for(int i=0 ; i< N ; i++)dp[i] =0;
        sort(all(w));
        cout << w.size() << ' ' ;
        for(auto it:w)cout <<it << ' ';
        cout << nn
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 1272 KB Output is correct
2 Correct 121 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 1104 KB Output is correct
2 Correct 407 ms 1248 KB Output is correct
3 Correct 430 ms 1248 KB Output is correct
4 Correct 618 ms 1104 KB Output is correct
5 Correct 846 ms 1296 KB Output is correct
6 Correct 1093 ms 1104 KB Output is correct
7 Correct 1053 ms 1344 KB Output is correct