답안 #1040268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040268 2024-07-31T21:29:05 Z kl0989e Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 9748 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()

void solve() {
    int n;
    cin >> n;
    vi a(n);
    int sum=0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        sum+=a[i];
    }
    vector<bitset<100001>> sets(n,0);
    for (int i=0; i<n; i++) {
        sets[i][50000]=1;
        sets[i]=(sets[i]<<a[i])|(sets[i]>>a[i]);
    }
    vi ans;
    for (int i=1; i<n; i++) {   
        bool ok=1;
        for (int j=0; j+i<n; j++) {
            sets[j]=(sets[j]<<a[j+i])|(sets[j]>>a[j+i]);
            if (!sets[j][50000]) {
                ok=0;
            }
        }
        if (ok) {
            ans.pb(i+1);
        }
    }
    cout << ans.size() << ' ';
    for (auto a:ans) {
        cout << a << ' ';
    }
    cout << '\n';
}

int32_t main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 2004 KB Output is correct
2 Correct 432 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1791 ms 6520 KB Output is correct
2 Execution timed out 2071 ms 9748 KB Time limit exceeded
3 Halted 0 ms 0 KB -