답안 #1019920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019920 2024-07-11T10:41:54 Z AndrijaM Kpart (eJOI21_kpart) C++14
100 / 100
501 ms 1272 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;
const int maxs=1e5+10;
const int logn=20;

int n;
int dp[maxs];
int ans[maxn];

signed main()
{
    ///freopen("sirbun.in","r",stdin);
    ///freopen("sirbun.out","w",stdout);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        memset(dp,0,sizeof dp);
        for(int i=0;i<=n;i++)
        {
            ans[i]=1;
        }
        int a[n+1];
        int S=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            S+=a[i];
            for(int j=S;j>=a[i];j--)
            {
                dp[j]=max(dp[j],dp[j-a[i]]);
            }
            dp[0]=dp[a[i]]=i;
            int sum=0;
            for(int j=i;j>=1;j--)
            {
                sum+=a[j];
                if(sum%2==1 || dp[sum/2]<j)
                {
                    ans[i-j+1]=0;
                }
            }
        }
        int kol=0;
        for(int i=1;i<=n;i++)
        {
            kol+=ans[i];
        }
        cout<<kol<<" ";
        for(int i=1;i<=n;i++)
        {
            if(ans[i])
            cout<<i<<" ";
        }
        cout<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 8 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1272 KB Output is correct
2 Correct 75 ms 1112 KB Output is correct
3 Correct 85 ms 1116 KB Output is correct
4 Correct 154 ms 1112 KB Output is correct
5 Correct 392 ms 1268 KB Output is correct
6 Correct 501 ms 1116 KB Output is correct
7 Correct 448 ms 1116 KB Output is correct