Submission #642370

# Submission time Handle Problem Language Result Execution time Memory
642370 2022-09-19T10:28:18 Z glupan Kpart (eJOI21_kpart) C++14
0 / 100
2000 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

int a[1001];

bool reachable(int p, int r, int sum) {
    if(sum==0) return 1;
    else if(sum<0) return 0;
    if(p==r) return 0;
    return max(reachable(p+1, r, sum-a[p]), reachable(p+1, r, sum));
}

void solve() {
    int n;
    cin >> n;
    int pref[n+1];
    pref[0]=0;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        pref[i]=pref[i-1]+a[i];
    }
    vector<int>ans;
    for(int i=2; i<=n; i++) {
        bool pos=1;
        for(int j=1; j<=n-i+1; j++) {
            int x=pref[j+i-1]-pref[j-1];
            if(x%2) {
                pos=0;
                break;
            }
            x/=2;
            if(!reachable(j, j+i, x)) pos=0;
        }
        if(pos) ans.push_back(i);
    }
    cout << ans.size() << " ";
    for(int i=0; i<ans.size(); i++) cout << ans[i] << " ";
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while(t--)
        solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0; i<ans.size(); i++) cout << ans[i] << " ";
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2004 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2078 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -