Submission #524585

# Submission time Handle Problem Language Result Execution time Memory
524585 2022-02-09T15:13:33 Z Nursik Kpart (eJOI21_kpart) C++14
100 / 100
939 ms 912 KB
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
 
const ll maxn = 1e5 + 1, maxm = 5e4 + 1,  maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31;
using namespace std;
 
int t, n;
int a[maxn], pref[maxn], pos[maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        vector<int> ans;
        for (int i = 1; i <= n; ++i){
            cin >> a[i];
            pref[i] = pref[i - 1] + a[i];
            ans.pb(i);
        }
        for (int i = 0; i <= pref[n]; ++i){
            pos[i] = -1;
        }
        pos[0] = 0;
        for (int i = 1; i <= n; ++i){
            for (int j = maxm - 1; j >= 0; --j){
                if (pos[j] != -1 && j + a[i] <= maxm - 1){
                    pos[j + a[i]] = max(pos[j + a[i]], pos[j]);
                }
            }
            pos[a[i]] = i;
            vector<int> next;
            for (auto it : ans){
                if (it > i){
                    next.pb(it);
                    continue;
                }
                ll sum = pref[i] - pref[i - it];
                if (sum % 2 == 0 && pos[sum / 2] >= i - it + 1){
                    next.pb(it);
                }
            }
            ans = next;
        }
        cout << ans.size() << " ";
        for (auto it : ans){
            cout << it << " ";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 500 KB Output is correct
2 Correct 114 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 508 KB Output is correct
2 Correct 360 ms 532 KB Output is correct
3 Correct 342 ms 460 KB Output is correct
4 Correct 493 ms 680 KB Output is correct
5 Correct 744 ms 752 KB Output is correct
6 Correct 939 ms 892 KB Output is correct
7 Correct 871 ms 912 KB Output is correct