This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 5e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k;
int a[MAXN];
void read()
{
cin >> n >> k;
for (int i = 1; i <= n; ++ i)
cin >> a[i];
}
int p[MAXN], used[MAXN];
void check()
{
int cnt_false = 0;
for (int i = 1; i <= n; ++ i)
{
if(cnt_false < p[i])
{
cnt_false ++;
}
}
if(cnt_false == k)
{
for (int i = 1; i <= n; ++ i)
cout << p[i] << " ";
cout << endl;
exit(0);
}
}
void gen(int pos)
{
if(pos > n)
{
check();
return;
}
for (int i = 1; i <= n; ++ i)
{
if(!used[i])
{
used[i] = 1;
p[pos] = a[i];
gen(pos+1);
used[i] = 0;
}
}
}
int main()
{
speed();
read();
gen(1);
cout << -1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |