답안 #839658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839658 2023-08-30T11:33:43 Z alishejhf Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 456 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>

#define ent '\n'
#define fi first
#define se second
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) x.begin(),x.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const int inf = (int)(1e9 + 7);
const ll INF = (ll)(2e18 + 7);
const ld eps = (ld)(1e-12);
const int dx[] = { -1,0,1,0,1,1,-1,-1 }, dy[] = { 0,1,0,-1,1,-1,1,-1 };
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
int n,a[N],cnt[N];
bitset<50001> dp;
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt[i]=0;
    }
    for(int i=1;i<=n;i++){
        ll sum=0;
        dp.reset();
        dp[0]=1;
        for(int j=i;j<=n;j++){
            sum+=a[j];
            dp|=dp<<a[j];
            if(sum&1) continue;
            if((sum>>1)>5e4){
                break;
            }
            if(dp[sum>>1]){
                ++cnt[j-i+1];
            }
        }
    }
    vector<int> ans;
    for(int i=1;i<=n;i++){
        if(cnt[i]==n-i+1){
            ans.pb(i);
        }
    }
    cout<<sz(ans)<<' ';
    for(auto it:ans){
        cout<<it<<' ';
    }
    cout<<ent;
    return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    srand(time(0));
    //freopen(".in", "r", stdin);
    //freopen(".out","w",stdout);
    int ttt=1;
    cin>>ttt;
    for(int i=1;i<=ttt;i++){
        //cout<<"NEWCASE"<<ent;
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 344 KB Output is correct
2 Correct 124 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 536 ms 456 KB Output is correct
2 Correct 1425 ms 344 KB Output is correct
3 Correct 1663 ms 340 KB Output is correct
4 Execution timed out 2082 ms 340 KB Time limit exceeded
5 Halted 0 ms 0 KB -