이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//don't copy pls)
/*TAAK ZDES NADO RECURSIU PISAT*/
//I'm not in the danger i am the DANGER
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define sigma signed
using namespace std;
using namespace __gnu_pbds;
const int N = 1e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,a[N],p[N],dp[121][N];
void Gold(){
cin >> n;
for(int i = 1 ; i <= n ; i++){
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
vector <int> ans;
for(int k = 2 ; k <= n ; k++){
bool ok = 1;
// for(int i = 1 ; i <= n ; i++){
// cout << p[i] << ' ';
// }
// cout << '\n';
for(int i = k ; i <= n ; i++){
int sum = p[i] - p[i - k];
if(sum % 2){
ok = 0;
break;
}
sum /= 2;
for(int j = i - k ; j <= i ; j++){
for(int x = 1 ; x <= sum ; x++){
dp[j][x] = 0;
}
}
for(int j = i - k + 1 ; j <= i ; j++){
dp[j][0] = 1;
}
for(int j = i - k + 1 ; j <= i ; j++){
for(int x = 1 ; x <= sum ; x++){
dp[j][x] = max(dp[j - 1][x] , dp[j][x]);
if(x >= a[j]){
dp[j][x] = max(dp[j][x] , dp[j - 1][x - a[j]]);
}
}
}
bool okok = 0;
for(int j = i - k + 1 ; j <= i ; j++){
if(dp[j][sum]){
okok = 1;
break;
}
}
if(!okok){
ok = 0;
break;
}
}
if(ok){
ans.pb(k);
}
}
cout << ans.size() << ' ';
for(auto it : ans){
cout << it << ' ';
}
cout << '\n';
}
sigma main(){
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
int TT = 1;
cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Gold();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |