이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1e3 + 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 () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
sm += a[i];
}
set < int > s;
for (int i = 1; i <= n; i++) s.insert(i), gg[i] = 0;
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |