#include <iostream>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <numeric>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>
using namespace std;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
void docase()
{
int n;
cin >> n;
vector<int> a(n), dp(50005, -1);
int c[1001] { 0 };
for (auto &x : a) cin >> x;
for (int sum = 0, i = 0; i < n; ++i)
{
sum += a[i];
for (int j = 50000; j >= a[i]; --j)
{
if (j - a[i] >= 0 && dp[j - a[i]] != -1) dp[j] = max(dp[j], dp[j - a[i]]);
else if (j - a[i] == 0) dp[j] = i + 1;
}
for (int sub = sum, j = 0; j <= i; ++j)
{
if (!(sub & 1) && dp[sub / 2] >= j + 1);
else
c[i-j+1] = 1;
sub -= a[j];
}
}
cout << n - accumulate(ALL(c), 0) << ' ';
for (auto i = 1; i <= n; ++i)
if (!c[i]) cout << i << ' ';
cout << '\n';
}
int main()
{
ShinLena;
int T;
cin >> T;
while (T--) docase();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
628 KB |
Output is correct |
2 |
Correct |
270 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
567 ms |
632 KB |
Output is correct |
2 |
Correct |
1122 ms |
716 KB |
Output is correct |
3 |
Correct |
1187 ms |
912 KB |
Output is correct |
4 |
Correct |
1737 ms |
648 KB |
Output is correct |
5 |
Execution timed out |
2055 ms |
884 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |