#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
#pragma GCC target ("avx")
using namespace std ;
const int maxn = 1e5 + 10 , maxq = 1e3+10 , mod = 998244353 ,inf = 1e9 ;
int a[maxn] , dp[maxq][maxn] , pre[maxn] ;
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t ;
cin >> t ;
while(t--){
int n ;
cin >> n ;
for(int i =1 ; i<= n ; i++){
cin >> a[i] ;
pre[i] = pre[i-1] + a[i] ;
}
for(int i = 0; i <= n ; i++){
for(int j = 0 ; j <= (maxn-10) ; j++){
dp[i][j] = -1 ;
}
}
dp[0][0] = 0 ;
for(int i = 1; i <= n ; i++){
for(int j = 0 ; j <= (maxn-10) ; j++){
dp[i][j] = dp[i-1][j] ;
if(a[i] <= j){
dp[i][j] = max(dp[i-1][j-a[i]] , dp[i][j]);
}
if(j == a[i] && j != 0)dp[i][j] = i ;
else if(dp[i][j] == 0 && j == 0)dp[i][j] =0 ;
}
}
// for(int i = 1; i<= n ; i++){
// for(int j = 0 ; j <= 8 ; j ++){
// cout << dp[i][j] << " " ;
// }
// cout << "\n";
// }
vector <int> v;
for(int i =1 ;i <= n ; i++){
int x = 1 , ok = 0;
for(int j = i ; j <= n ; j++){
int sum = pre[j] - pre[x-1] ;
if(sum % 2 == 1){
ok = 1;
break;
}
if(dp[j][sum/2] < x || dp[j][sum/2] == -1){
// cout << dp[j][sum/2] << " " <<i << " " << j << " " << sum << "<-\n";
ok = 1 ;
break;
}
x++;
}
if(ok == 0)v.pb(i);
}
cout << v.size() << " " ;
for(int i = 0 ; i <v.size();i++){
cout << v[i] << " " ;
}
cout << "\n";
}
return 0 ;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0 ; i <v.size();i++){
| ~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
12448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
277 ms |
26932 KB |
Output is correct |
2 |
Correct |
541 ms |
46500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1033 ms |
100884 KB |
Output is correct |
2 |
Correct |
1803 ms |
150720 KB |
Output is correct |
3 |
Correct |
1844 ms |
170200 KB |
Output is correct |
4 |
Execution timed out |
2096 ms |
221132 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |