답안 #637837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637837 2022-09-03T11:58:34 Z ksu2009en Kpart (eJOI21_kpart) C++17
10 / 100
2000 ms 676 KB
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")

#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>

#define endl '\n'

using namespace std;
typedef int ll;

bitset<1000007>bs;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll t;
    cin >> t;
    
    while(t--){
        ll n;
        cin >> n;
        
        vector<ll>a(n);
        for(int i = 0; i < n; i++)
            cin >> a[i];
        
        vector<ll>pref(n);
        pref[0] = a[0];
        
        for(int i = 1; i < n; i++)
            pref[i] = pref[i - 1] + a[i];
        
        vector<ll>can(n + 1);
        
        for(int i = 2; i <= n; i++){
            if(can[i] != 0)
                continue;
            
            bool ok = false;
            
            for(int j = 0; j + i - 1 < n; j++){
                if((pref[j + i - 1] - (j > 0 ? pref[j - 1] : 0)) % 2 != 0){
                    ok = true;
                    continue;
                }
                bs = 0;
                
                bs[a[j]] = 1;
                
                ll sum = a[j];
                
                for(int k = j + 1; k < j + i; k++){
                    bs |= (bs << a[k]);
                    sum += a[k];
                }
                
                if(sum % 2 == 0 && (bs[sum / 2])){
                    continue;
                }
                ok = true;
                break;
            }
            
            if(!ok){
                can[i] = 1;
                
                for(int j = i; j <= n; j += i)
                    can[j] = 1;
            }
            else{
                can[i] = -1;
                
                for(int j = i; j <= n; j+= i)
                    can[i] = -1;
            }
        }
        
        vector<ll>ans;
        
        for(int i = 2; i <= n; i++)
            if(can[i] == 1)
                ans.push_back(i);
        
        cout << ans.size() << ' ';
        for(auto i: ans)
            cout << i << ' ';
        cout << endl;
    }
    
    return 0;
}
/*
 3 1
 3 4 5
 1 2 90
 
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2077 ms 664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2086 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -