답안 #1089460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089460 2024-09-16T14:38:19 Z vjudge1 Kpart (eJOI21_kpart) C++17
100 / 100
1414 ms 1372 KB
#include <bits/stdc++.h>

#define int         long long
#define all(x)     x.begin(), x.end()
#define allr(x)     x.rbegin(), x.rend()
#define sz          size()
#define yes      "YES"
#define no      "NO"
#define IOI      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pf      push_front
#define pb      push_back
#define S      second
#define F      first

using namespace std;

const int N = 1e5 + 29;
const int NN = 1e5;
const int mod = (1e9 + 7);
const int inf = 1e18;

int a[N], pref[N], dp[N];

void legenda_ne_umret() {
    int n;
    cin >> n;
    for (int i = 0; i < N; i++) dp[i] = 0;
    set<int> st;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
        if (i > 1) st.insert(i);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = N - 9; j > a[i]; j--) {
            dp[j] = max(dp[j], dp[j - a[i]]);
        }
        dp[a[i]] = i;
        for (int j = 2; j <= i; j++) {
            int sum = pref[i] - pref[i - j];
            if (sum % 2 || dp[sum / 2] < i - j + 1) {
                st.erase(j);
            }
        }
    }
    cout << st.sz << ' ';
    for (auto i : st) cout << i << ' ';
}



signed main() {
    IOI;
//    freopen("maze.in", "r", stdin);
//    freopen("maze.out", "w", stdout);
/////////////////////////////////////////////
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case " << i << ":\n";
        legenda_ne_umret();
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 1116 KB Output is correct
2 Correct 146 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 1116 KB Output is correct
2 Correct 560 ms 1260 KB Output is correct
3 Correct 571 ms 1112 KB Output is correct
4 Correct 805 ms 1312 KB Output is correct
5 Correct 1119 ms 1332 KB Output is correct
6 Correct 1412 ms 1372 KB Output is correct
7 Correct 1414 ms 1360 KB Output is correct