답안 #634390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634390 2022-08-24T10:51:38 Z giorgikob Kpart (eJOI21_kpart) C++14
100 / 100
1565 ms 197392 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define count1(x) __builtin_popcount(x)
#define endl '\n'
using namespace std;

const int N = 1e3+1, mod = 1e6, M = 5e4;

vector<int>pre(N+1, 0);
vector<vector<int>> ind(N+1, vector<int>(M+1, 0));

inline void test_case(){

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        pre[i] = pre[i-1] + x;
        for(int sum = 0; sum <= M; sum++){
            ind[i][sum] = ind[i-1][sum];
            if(sum == x){
                ind[i][sum] = i;
            } else if(sum > x && ind[i][sum] < ind[i-1][sum-x]){
                ind[i][sum] = ind[i-1][sum-x];
            }
        }
    }

    vector<int> ans;
    for(int k = 1; k <= n; k++){
        bool ok = true;
        for(int l = 1; l+k-1 <= n; l++){
            int r = l+k-1;
            int sum = pre[r] - pre[l-1];
            if(sum % 2 != 0 || ind[r][sum/2] < l){
                ok = false;
                break;
            }
        }
        if(ok){
            ans.pb(k);
        }
    }

    cout << ans.size() << " ";
    for(auto x : ans){
        cout << x << " ";
    }
    cout << endl;
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int T = 1;
    cin >> T;
    while(T--){
        test_case();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 197212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 197232 KB Output is correct
2 Correct 215 ms 197232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 197196 KB Output is correct
2 Correct 591 ms 197208 KB Output is correct
3 Correct 607 ms 197196 KB Output is correct
4 Correct 857 ms 197268 KB Output is correct
5 Correct 1298 ms 197196 KB Output is correct
6 Correct 1565 ms 197208 KB Output is correct
7 Correct 1429 ms 197392 KB Output is correct