#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 long long ll;
bitset<1000007>bs;
vector<ll>slow(ll n, vector<ll>a){
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);
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(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<vector<ll>>can(n + 1, vector<ll>(n + 1));
for(int i = 0; i < n; i++){
bs = 0;
bs[a[i]] = 1;
ll sum = a[i];
for(int j = i + 1; j < n; j++){
sum += a[j];
bs |= (bs << a[j]);
bs[a[j]] = 1;
if(sum % 2 == 0 && bs[sum / 2])
can[i][j - i + 1] = 1;
}
}
/*
for(int i = 0; i < n; i++){
for(int j = 0; j <= n; j++)
cout << can[i][j] << ' ';
cout << endl;
}
*/
vector<ll>ans;
for(int j = 2; j <= n; j++){
bool ok = false;
for(int i = 0; i < n; i++){
if(i + j - 1 >= n)
continue;
if(!can[i][j])
ok = true;
}
if(!ok)
ans.push_back(j);
}
cout << ans.size() << ' ';
for(auto i: ans)
cout << i << ' ';
cout << endl;
/*
if(ans != slow(n, a)){
cout << n << endl;
for(auto i: a)
cout << i << ' ';
cout << endl;
for(auto i: ans)
cout << i << ' ';
cout << endl;
auto y = slow(n, a);
for(auto i: y)
cout << i << ' ';
cout << endl;
return 0;
}
*/
}
return 0;
}
/*
1
10
28 23 18 28 83 22 79 64 80 33
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
748 ms |
836 KB |
Output is correct |
2 |
Execution timed out |
2079 ms |
932 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2068 ms |
1172 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |