Submission #524582

# Submission time Handle Problem Language Result Execution time Memory
524582 2022-02-09T15:10:51 Z Nursik Kpart (eJOI21_kpart) C++14
30 / 100
362 ms 852 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 = 1e3 + 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[maxm];
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;
                }
                int 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 22 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 444 KB Output is correct
2 Correct 113 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 544 KB Output is correct
2 Correct 362 ms 536 KB Output is correct
3 Correct 344 ms 544 KB Output is correct
4 Runtime error 1 ms 852 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -