| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 821389 | danikoynov | Watermelon (INOI20_watermelon) | C++14 | 276 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... | ||||
