#include <iostream>
#include <vector>
using namespace std;
void monstro(vector<int> &city, const vector<int> &dad, vector<int> &order, bool &pr)
{
if(city.size() == dad.size())
{
if(city == dad)
{
cout << order.size() << "\n";
for(auto x : order)
{
cout << x << " ";
}
cout << "\n";
pr = true;
return;
}
else return;
}
else
{
for(unsigned int k = 1; k < city.size() - 1; k++)
{
order.push_back(city[k]);
vector<int> cityy = city;
cityy.erase(cityy.begin() + (k + 1));
cityy.erase(cityy.begin() + (k - 1));
monstro(cityy, dad, order, pr);
order.pop_back();
if(pr) k = city.size();
}
}
return;
}
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
int n, q;
cin >> n >> q;
vector<int> city(n, 0);
for(int j = 0; j < n; j++) city[j] = j + 1;
vector<int> dad(q, 0);
for(int j = 0; j < q; j++) cin >> dad[j];
if(((n - q) % 2 != 0) || (n < q)) cout << -1 << "\n";
else
{
vector<int> p;
bool pr = false;
monstro(city, dad, p, pr);
if(!pr) cout << -1 << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
476 KB |
Time limit exceeded |
4 |
Execution timed out |
1073 ms |
504 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
256 KB |
Time limit exceeded |
2 |
Execution timed out |
1069 ms |
376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
476 KB |
Time limit exceeded |
4 |
Execution timed out |
1073 ms |
504 KB |
Time limit exceeded |
5 |
Execution timed out |
1082 ms |
376 KB |
Time limit exceeded |
6 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
7 |
Execution timed out |
1073 ms |
376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
476 KB |
Time limit exceeded |
4 |
Execution timed out |
1073 ms |
504 KB |
Time limit exceeded |
5 |
Execution timed out |
1082 ms |
376 KB |
Time limit exceeded |
6 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
7 |
Execution timed out |
1073 ms |
376 KB |
Time limit exceeded |
8 |
Execution timed out |
1083 ms |
376 KB |
Time limit exceeded |
9 |
Execution timed out |
1078 ms |
376 KB |
Time limit exceeded |
10 |
Execution timed out |
1091 ms |
376 KB |
Time limit exceeded |
11 |
Execution timed out |
1075 ms |
376 KB |
Time limit exceeded |