# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
821389 | danikoynov | Watermelon (INOI20_watermelon) | C++14 | 276 ms | 460 KiB |
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;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 11;
int p[maxn], used[maxn], b[maxn], n, k;
vector < vector < int > > pw;
void check()
{
stack < int > st;
for (int i = 1; i <= n; i ++)
{
int cnt = 0;
while(!st.empty() && p[st.top()] < p[i])
{
cnt ++;
if (b[st.top()] != cnt)
return;
st.pop();
}
st.push(i);
}
while(!st.empty())
{
if (b[st.top()] != -1)
return;
st.pop();
}
vector < int > cur;
for (int i = 1; i <= n; i ++)
cur.push_back(p[i]);
pw.push_back(cur);
}
bool cmp(vector < int > l, vector < int > r)
{
for (int i = 1; i <= n; i ++)
{
int p1 = 0;
while(l[p1] != i)
p1 ++;
int p2 = 0;
while(r[p2] != i)
p2 ++;
if (p1 == p2)
continue;
return p1 < p2;
}
}
void perm(int pos)
{
if (pos == n + 1)
check();
else
{
for (int i = 1; i <= n; i ++)
{
if (!used[i])
{
p[pos] = i;
used[i] = 1;
perm(pos + 1);
used[i] = 0;
p[pos] = 0;
}
}
}
}
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i ++)
cin >> b[i];
perm(1);
if (pw.size() < k)
{
cout << -1 << endl;
}
else
{
sort(pw.begin(), pw.end(), cmp);
for (int v : pw[k - 1])
cout << v << " ";
cout << endl;
}
/**for (vector < int > cur : pw)
{
for (int v : cur)
cout << v << " ";
cout << endl;
}*/
}
int main()
{
solve();
return 0;
}
Compilation message (stderr)
# | 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... |