#include "bits/stdc++.h"
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
if (!m) {
cout << -1 << '\n';
return;
}
vector<int> a(n);
for (int i = 0; i < m; i++) {
int x;
cin >> x;
x--;
a[x] = 1;
}
vector<int> ans, tmp;
int want = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
if (want) {
cout << -1 << '\n';
return;
}
while ((int) tmp.size() >= 3) {
ans.push_back(tmp.end()[-2]);
tmp.pop_back();
tmp.pop_back();
tmp.pop_back();
tmp.push_back(ans.back());
}
want = (int) tmp.size();
tmp.clear();
for (int j = 0; j < want; j++) {
ans.push_back(i);
}
} else {
if (want) {
want--;
} else {
tmp.push_back(i);
}
}
}
if (!tmp.empty() || want) {
cout << -1 << '\n';
return;
}
cout << (int) ans.size() << '\n';
for (auto& i : ans) {
cout << i + 1 << " ";
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
1240 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1524 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
1660 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
1364 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
1376 KB |
Output isn't correct |