답안 #1107573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107573 2024-11-01T14:43:14 Z vjudge1 Kpart (eJOI21_kpart) C++17
100 / 100
1102 ms 6724 KB
#include <bits/stdc++.h>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ff first
#define int long long
#define ss second
#define pb push_back
#define y1 zildjian

using namespace std;

const int N = 3e6+100;
const int INF = 1e18;
const int mod = 1e9+7;
const int dx[] = {-1,-1,0,1,1,1,0,-1,0};
const int dy[] = {0,1,1,1,0,-1,-1,-1,0};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int binpow (int a, int n){
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return (binpow (a, n-1)%mod * a%mod)%mod;
	else {
		int b = binpow (a, n/2) % mod;
		return (b%mod * b%mod)%mod;
	}
}

int n;
int a[N];
int cnt[N];
int dp[N];
int pref[N];

void solve(){
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        cnt[i] = 0;
        pref[i] = pref[i-1]+a[i];
    }
    for(int i = 0;i<=1e5;i++) dp[i] = 0;
    for(int i = 1;i<=n;i++){
        for(int k = 1e5;k>a[i];k--){
            dp[k] = max(dp[k],dp[k-a[i]]);
        }
        dp[a[i]] = i;
        for(int k = 2;i-k+1>=1;k++){
            int s = pref[i]-pref[i-k];
            if(s%2 == 0 && dp[s/2] > i-k){
                cnt[k]++;
            }
        }
    }
    vector<int> ans;
    for(int i = 1;i<=n;i++) if(cnt[i] == (n-i+1)) ans.pb(i);
    cout<<ans.size()<<' ';
    for(auto x:ans) cout<<x<<' ';
    cout<<'\n';
}   

signed main(){
    // freopen("floyd.in","r",stdin); 
    // freopen("floyd.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int T = 1;
    cin>>T;
    for(int i = 1;i<=T;i++){
        // cout<<"Case "<<i<<": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 6480 KB Output is correct
2 Correct 123 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 6480 KB Output is correct
2 Correct 424 ms 6652 KB Output is correct
3 Correct 443 ms 6628 KB Output is correct
4 Correct 589 ms 6480 KB Output is correct
5 Correct 853 ms 6640 KB Output is correct
6 Correct 1102 ms 6724 KB Output is correct
7 Correct 1045 ms 6704 KB Output is correct