#include <cmath>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
#pragma GCC target("avx2,avx,sse,sse2,sse3,sse4,ssse3")
#pragma GCC optimize("O3")
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t;
cin>>t;
int largest = 500000;
unordered_set<int> kavlues;
vector<int> pos;
vector<int> pos_swap;
for (int test = 0; test < t; test++) {
int n;
cin>>n;
kavlues.clear();
pos.clear();
pos_swap.clear();
for (int i = 2; i <= n; i++) {
kavlues.insert(i);
}
pos.resize(largest + 1, - 1);
pos_swap.resize(largest + 1, -1);
pos[0] = 0;
pos_swap[0] = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin>>a[i];
}
for (int i = 0; i < n; i++) {
for (int s = largest; s >= 0; s--) {
if (s - a[i] < 0) {
break;
}
pos[s] = max(pos[s - a[i]], pos[s]);
}
pos[a[i]] = i;
int sum = 0;
for (int j = i; j >= 0; j--) {
sum += a[j];
int amount = i - j + 1;
if (amount < 2) {
continue;
}
bool erase = false;
if (sum & 1) {
erase = true;
}
if (pos[sum >> 1] < j) {
erase = true;
}
if (erase && kavlues.find(amount) != kavlues.end()) {
kavlues.erase(amount);
}
}
}
vector<int> res;
for (auto& el : kavlues) {
res.push_back(el);
}
sort(res.begin(), res.end());
cout << res.size() << " ";
for (auto& el : res) {
cout << el << " ";
}
cout << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
359 ms |
4396 KB |
Output is correct |
2 |
Correct |
712 ms |
4372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1347 ms |
4188 KB |
Output is correct |
2 |
Execution timed out |
2045 ms |
4404 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |