Submission #1128204

#TimeUsernameProblemLanguageResultExecution timeMemory
1128204asdfghjkKpart (eJOI21_kpart)C++20
0 / 100
2094 ms1360 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define all(x) x.begin(), x.end()
#define con continue
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;


const ll N = 1e5 + 5;
const ll NN =   1e6 + 1e5;
const ll INF = 1e18;
const ll inf = 1e9;
const ll MOD = 1e9 + 7;
int a[N],pre[N],cnt[N];
void solve(){
    int n;cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        pre[i] =pre[i - 1] + a[i];
    }
    for(int i = 2;i <= n;i++){
        set <int> dp;
        dp.clear();
        dp.insert(a[i]);
        dp.insert(0);
        for(int j = i - 1;j > 0;j--){
            set <int> ndp;
            for(int to : dp){
                ndp.insert(to);
                ndp.insert(to + a[j]);
            }
            dp = ndp;
            int sum = pre[i] - pre[j - 1];
            if(sum % 2 == 0 && dp.count((sum / 2)) == 1){
                cnt[(i - j + 1)]++;
            }
        }
    }
    vector <int> ans;
    ans.clear();
    for(int i = 2;i <= n;i++){
        if(cnt[i] == n - i + 1){
            ans.pb(i);
        }
    }
    cout << ans.size() << ' ';
    for(int to : ans){
        cout << to << ' ';
    }
    cout << '\n';
}

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
    ll abd = 1;
    cin >>abd;
//    freopen("promote.in","r",stdin);
//    freopen("promote.out","w",stdout);
    for(ll i = 1;i <= abd;i++){

        solve();
    }
}

Compilation message (stderr)

Main.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...