#include <bits/stdc++.h>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define f first
#define s second
#define d(a) (a * (a + 1)) / 2
#define ent '\n'
#define emb emplace_back
typedef double db;
using namespace std;
using namespace __gnu_pbds;
const ll inf = 1e18 + 7;
const int mod = 1e9 + 7;
const int N = 1e5 + 7;
const int INF = 2e9;
void ALLAHU_AKBAR() {
ios_base::sync_with_stdio (0);
cin.tie (0);
// freopen("closing.in","r",stdin);
// freopen("closing.out","w",stdout);
}
ll binpow (ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n - 1) * a;
else {
ll b = binpow (a, n / 2);
return b * b;
}
}
int n, sm, a[N], gg[N], pr[N];
void solve () {
set < int > s;
cin >> n;
sm = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
sm += a[i];
s.insert(i);
}
for (int i = 1; i <= 1e5; i++) gg[i] = 0;
s.erase(1);
for (int i = 1; i <= n; i++) {
for (int j = sm; j >= a[i]; j--) gg[j] = max(gg[j], gg[j - a[i]]);
gg[a[i]] = i;
for (int j = 1; j < i; j++) {
if ((pr[i] - pr[j - 1]) % 2 || j > gg[(pr[i] - pr[j - 1]) / 2]) s.erase((i - j + 1));
}
}
cout << s.size() << ' ';
for (auto x : s) cout << x << " ";
cout << '\n';
}
int main() {
ALLAHU_AKBAR();
int IOI = 1;
cin >> IOI;
int g = 0;
while (-- IOI + 1) {
g++;
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
856 KB |
Output is correct |
2 |
Correct |
17 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
860 KB |
Output is correct |
2 |
Correct |
205 ms |
872 KB |
Output is correct |
3 |
Correct |
212 ms |
856 KB |
Output is correct |
4 |
Correct |
394 ms |
896 KB |
Output is correct |
5 |
Correct |
937 ms |
856 KB |
Output is correct |
6 |
Correct |
1296 ms |
960 KB |
Output is correct |
7 |
Correct |
1189 ms |
904 KB |
Output is correct |