Submission #615967

# Submission time Handle Problem Language Result Execution time Memory
615967 2022-07-31T16:29:08 Z kideso Kpart (eJOI21_kpart) C++17
10 / 100
2000 ms 876 KB
#include <iostream>
#include <queue>
#include <algorithm>

//#include <fstream>

using namespace std;

//ifstream F("be.txt");

vector<int> ans, x, s;
int N;
const int maxN = 1e5;

void DP(int k){
    vector<int> dp;
    dp.push_back(0);

    int sum = 0;
    for(int i = k; i < N; ++i){
        sum += x[i];
        
        for(int j = dp.size() - 1; j >= 0; --j)
            dp.push_back(dp[j] + x[i]);
        
        sort(dp.begin(), dp.end());
        auto it = unique(dp.begin(), dp.end());
        dp.resize(distance(dp.begin(), it));

        if(sum % 2 == 0 && binary_search(dp.begin(), dp.end(), sum / 2)) ++s[i - k + 1];
    }

    return;
}

int main(){
    int T;
    cin >> T;

    while(T--){
        ans.clear();

        cin >> N;
        x.assign(N, 0);
        s.assign(N + 1, 0);
        
        for(auto &e : x)
            cin >> e;

        for(int i = 0; i < N; ++i)
            DP(i);

        for(int i = 1; i <= N; ++i)
            if(s[i] == N - i + 1) ans.push_back(i);

        cout << ans.size() << ' ';
        for(auto e : ans)
            cout << e << ' ';
        cout << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 246 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 876 KB Time limit exceeded
2 Halted 0 ms 0 KB -