답안 #964867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964867 2024-04-17T16:47:08 Z zxcigan Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 172932 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;

template <typename T>
bool umx(T& a, T b) {
    return (a < b ? a = b, 1 : 0);
}
template <typename T>
bool umn(T& a, T b) {
    return (a > b ? a = b, 1 : 0);
}
int dp[1001][(int)5e4 + 2];
void solve () {
    int n;
    cin >> n;
    vector<int> a (n + 1);
    vector<int> pref (n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i], pref[i] = pref[i - 1] + a[i];
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= 5e4; ++j) dp[i][j] = dp[i - 1][j];
        dp[i][a[i]] = i;
        for (int j = 1; j <= 5e4; ++j) {
            if (j + a[i] > 5e4) break;
            umx (dp[i][j + a[i]], dp[i - 1][j]);
        }
    }
    vector<int> ans;
    for (int k = 1; k <= n; ++k) {
        bool bad = false;
        multiset<int> st;

        for (int l = 1; l <= k; ++l)  st.insert(a[l]);
        for (int l = 1; l <= n; ++l) {
            int r = l + k - 1;
            if (r > n) break;
            int s = pref[r] - pref[l - 1];
            if (s % 2) {
                bad = 1;
                break;
            }
            int x = (*st.rbegin());
            if (x > (s >> 1)) {
                bad = 1;
                break;
            }
            if (x != (s >> 1)) {
                if (dp[r][s >> 1] < l) {
                    bad = 1;
                    break;
                }
            }
            st.erase (st.find (a[l]));
            if (l + k <= n) st.insert(a[l + k]);
        }
        if (!bad) ans.push_back(k);
    }
    cout << (int)ans.size() << ' ';
    for (auto it : ans) cout << it << ' ';
    cout << "\n";
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //    freopen ("input.txt", "r", stdin);
//    freopen ("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 14932 KB Output is correct
2 Correct 171 ms 25084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 432 ms 51768 KB Output is correct
2 Correct 768 ms 75480 KB Output is correct
3 Correct 808 ms 85256 KB Output is correct
4 Correct 1277 ms 110728 KB Output is correct
5 Execution timed out 2045 ms 172932 KB Time limit exceeded
6 Halted 0 ms 0 KB -