Submission #538022

# Submission time Handle Problem Language Result Execution time Memory
538022 2022-03-16T03:16:21 Z rin_tohsaka Kpart (eJOI21_kpart) C++14
100 / 100
1068 ms 195968 KB
#include <bits/stdc++.h>
using namespace std;
int k[1010], p[1010], dp[1010][50010],c;
int main(){
    cin>>c;
    for(int cc = 0; cc < c; cc++){
        int n; cin >> n;     
        p[0] = 0;
        for (int i = 1; i <= n; i++){
          cin >> k[i];
        }
        for (int i = 1; i <= n; i++) p[i] = p[i-1] + k[i];
        vector<bool> work(n+1, 1);
        for (int i = 1; i <= n; i++){
            for (int x = 0; x < k[i]; x++) dp[i][x] = dp[i - 1][x];
            for (int x = k[i]; x< 50010; x++){
              dp[i][x] = max(dp[i - 1][x], dp[i - 1][x-k[i]]);
            }
            dp[i][k[i]] = i;
            for (int j = 1; j <= i; j++){
                int x = p[i] - p[j - 1];
                if (x % 2){
                  work[i+1-j] = 0;
                }
                else if (dp[i][x/ 2] < j){
                  work[i+1-j] = 0;
                }
            }
        }
        int ans=0;
        for (int i = 1; i <= n; i++)
            if (work[i])ans++;
                
        cout << ans << " ";
        for (int i = 1; i <= n; i++)
            if (work[i])cout << i << ' ';
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 13396 KB Output is correct
2 Correct 118 ms 23148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 50392 KB Output is correct
2 Correct 426 ms 75312 KB Output is correct
3 Correct 436 ms 85036 KB Output is correct
4 Correct 607 ms 110700 KB Output is correct
5 Correct 859 ms 171452 KB Output is correct
6 Correct 1068 ms 192980 KB Output is correct
7 Correct 977 ms 195968 KB Output is correct