#include <bits/stdc++.h>
#define pb push_back
using namespace std;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector <int> arr(n+2);
bool tf = 1;
for (int i = 1; i <= n; i++)
arr[i] = i;
arr[0] = arr[n+1] = 0;
for (int i = 0; i < k; i++) {
int a;
cin >> a;
arr[a] = 0;
}
if ((n - k) % 2) tf = 0;
int l = 1, r = 0;
vector <int> ans;
int cnt = 0;
int tmp = -1;
for (int i = 1; i <= n+1; i++) {
if (!arr[i]) {
if (!arr[i-1] && cnt) {
tf = 0;
break;
}
if (!arr[r]) {
l = i+1;
continue;
}
if (cnt > r-l+1) {
tf = 0;
break;
}
int c = r-l+1;
if (cnt == 1) {
if (c % 2) {
for (int j = 0; j < c/2; j++)
ans.pb((r+l)/2);
ans.pb(tmp);
cnt = 0, tmp = -1;
} else {
for (int j = 0; j < c/2-1; j++)
ans.pb((r+l)/2);
ans.pb(tmp);
cnt = 1, tmp = i;
}
} else if (cnt == 2) {
if (c % 2) {
for (int j = 0; j < c/2-1; j++)
ans.pb((r+l)/2);
ans.pb(tmp), ans.pb(tmp);
cnt = 1, tmp = i;
} else {
cout << c/2-1 << endl;
for (int j = 0; j < c/2-1; j++)
ans.pb((r+l)/2);
ans.pb(tmp), ans.pb(tmp);
cnt = 0, tmp = i;
}
} else {
if (c % 2) {
for (int j = 0; j < c/2; j++)
ans.pb((r+l)/2);
cnt = 1, tmp = i;
} else {
for (int j = 0; j < c/2-1; j++)
ans.pb((r+l)/2);
cnt = 2, tmp = i;
}
}
l = r = i+1;
} else r = i;
}
if (cnt) tf = 0;
if (!tf) {
cout << -1 << "\n";
} else {
cout << ans.size() << "\n";
if (!ans.size()) cout << "\n";
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " \n"[i==ans.size()-1];
}
}
}
Compilation message
del13.cpp: In function 'int main()':
del13.cpp:87:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
del13.cpp:88:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | cout << ans[i] << " \n"[i==ans.size()-1];
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
384 KB |
Integer 0 violates the range [1, 17] |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
632 KB |
Integer 36 violates the range [1, 18] |
2 |
Incorrect |
3 ms |
1188 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
384 KB |
Integer 0 violates the range [1, 17] |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
384 KB |
Integer 0 violates the range [1, 83] |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
384 KB |
Integer 0 violates the range [1, 17] |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
384 KB |
Integer 0 violates the range [1, 83] |
8 |
Incorrect |
6 ms |
1152 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
1280 KB |
Integer -1 violates the range [1, 84] |
10 |
Incorrect |
7 ms |
1152 KB |
Output isn't correct |
11 |
Incorrect |
11 ms |
1536 KB |
Output isn't correct |