답안 #524584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524584 2022-02-09T15:12:46 Z Nursik Kpart (eJOI21_kpart) C++14
30 / 100
477 ms 588 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[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;
                }
                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 << " ";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 508 KB Output is correct
2 Correct 113 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 540 KB Output is correct
2 Correct 349 ms 544 KB Output is correct
3 Correct 353 ms 548 KB Output is correct
4 Incorrect 477 ms 588 KB Output isn't correct
5 Halted 0 ms 0 KB -