답안 #549139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549139 2022-04-15T09:46:43 Z spike1236 Kpart (eJOI21_kpart) C++14
0 / 100
135 ms 11432 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

int a[1010];
int dp[1001][50001];
int pref[1001];
int n;

void solve() {
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum += a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    for(int i = 1; i <= n; ++i) {
        int x = min(pref[i], sum / 2);
        for(int j = 1; j <= x; ++j) {
            dp[i][j] = dp[i][j - 1];
            if(j == a[i]) dp[i][j] = i;
            if(j > a[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]]);
        }
        if(pref[i] <= sum / 2) dp[i][pref[i]] = max(dp[i][pref[i]], 1);
    }
    veci ans;
    for(int len = 2; len <= n; ++len) {
        bool can = 1;
        for(int l = 1; l + len - 1 <= n; ++l) {
            int r = l + len - 1;
            int s = pref[r] - pref[l - 1];
            if(s & 1) {
                can = 0;
                break;
            }
            if(dp[r][s / 2] < l) {
                can = 0;
                break;
            }
        }
        if(can) ans.pb(len);
    }
    cout << sz(ans) << ' '; for(auto i : ans) cout << i << ' ';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int CNT_TESTS = 1;
    cin >> CNT_TESTS;
    for(int NUMCASE = 1; NUMCASE <= CNT_TESTS; ++NUMCASE) {
        solve();
        if(NUMCASE != CNT_TESTS) cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 135 ms 11432 KB Output isn't correct
2 Halted 0 ms 0 KB -