Submission #519029

# Submission time Handle Problem Language Result Execution time Memory
519029 2022-01-25T11:57:27 Z NintsiChkhaidze Kpart (eJOI21_kpart) C++14
30 / 100
2000 ms 342508 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
#define left (h<<1),l,((l+r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
using namespace std;

const int N = 1005,M = 50000;
int a[N],dp[N][M+5],p[N];

signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int t;
    cin>>t;
    
    while(t--){
        int n;
        cin>>n;
        
        for (int i = 1; i <= n; i++)
            cin>>a[i],p[i] = p[i - 1] + a[i];
        
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= 50000; j++)
                dp[i][j] = -1;
        
        dp[0][0] = 0;   
        for (int i = 1; i <= n; i++){
            for (int j = M; j >= 1; j--){
                if (a[i] == j) dp[i][j] = i;
                dp[i][j] = max(dp[i][j],dp[i - 1][j]);
                if (j + a[i] <= M) 
                    dp[i][j + a[i]] = max(dp[i][j+a[i]],dp[i - 1][j]);
            }
        }
        
        vector <int> ans; ans.clear();
        for (int i = 1; i <= n; i++){
            bool check = 1;
            for (int j = i; j <= n; j++){
                int s = p[j] - p[j - i];
                if (s%2 || dp[j][s/2] < j - i + 1) {check = 0; break;}
            }
            if (check) ans.pb(i);
        }
        cout<<ans.size()<<" ";
        for (int x: ans)
            cout<<x<<" ";
        cout<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 26452 KB Output is correct
2 Correct 312 ms 46120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 589 ms 100524 KB Output is correct
2 Correct 988 ms 150284 KB Output is correct
3 Correct 1039 ms 169812 KB Output is correct
4 Correct 1366 ms 221144 KB Output is correct
5 Execution timed out 2084 ms 342508 KB Time limit exceeded
6 Halted 0 ms 0 KB -