답안 #650702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650702 2022-10-14T18:19:21 Z sofija6 Kpart (eJOI21_kpart) C++14
100 / 100
1723 ms 196108 KB
#include <bits/stdc++.h>
#define ll int
#define MAXN 1010
#define MAXS 100010
using namespace std;
ll a[MAXN],dp[MAXN][MAXS/2],pref[MAXN];
bool yes[MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll t,n;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (ll i=1;i<=n;i++)
        {
            cin >> a[i];
            pref[i]=pref[i-1]+a[i];
        }
        for (ll i=1;i<=n;i++)
        {
            yes[i]=true;
            for (ll j=0;j<=pref[n]/2;j++)
                dp[i][j]=0;
        }
        for (ll i=1;i<=n;i++)
        {
            for (ll j=0;j<=pref[n]/2;j++)
            {
                if (j>=a[i])
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i]]);
                else
                    dp[i][j]=dp[i-1][j];
            }
            dp[i][a[i]]=i;
        }
        ll ans=n;
        for (ll i=1;i<=n;i++)
        {
            for (ll j=i;j<=n;j++)
            {
                if (!yes[j-i+1])
                    continue;
                if ((pref[j]-pref[i-1])&1 || dp[j][(pref[j]-pref[i-1])/2]<i)
                {
                    yes[j-i+1]=false;
                    ans--;
                }
            }
        }
        cout << ans << " ";
        for (ll i=1;i<=n;i++)
        {
            if (yes[i])
                cout << i << " ";
        }
        cout << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1608 KB Output is correct
2 Correct 20 ms 3940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 14236 KB Output is correct
2 Correct 261 ms 31672 KB Output is correct
3 Correct 292 ms 40172 KB Output is correct
4 Correct 532 ms 66760 KB Output is correct
5 Correct 1204 ms 162308 KB Output is correct
6 Correct 1723 ms 193108 KB Output is correct
7 Correct 1558 ms 196108 KB Output is correct