답안 #821254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821254 2023-08-11T08:24:30 Z PVM_pvm Watermelon (INOI20_watermelon) C++17
7 / 100
422 ms 764 KB
#include<bits/stdc++.h>
using namespace std;
#define MAXN 13
int b[MAXN],n,k;
struct perm
{
    int ch[MAXN];
    perm(int a[])
    {
        for (int q=1;q<=n;q++) ch[q]=a[q];
    }
    void show()
    {
        //cout<<"P:";
        for (int q=1;q<=n;q++) cout<<ch[q]<<" ";
        cout<<"\n";
    }
};
vector<perm> ans;
int cur[MAXN],sb[MAXN];
bool dt[MAXN];
void check()
{
    for (int q=1;q<=n;q++) sb[q]=-1;
    for (int q=1;q<=n;q++) dt[q]=false;
    for (int tm=1;true;tm++)
    {
        bool smyrt=false;
        for (int q=1;q<=n;q++)
        {
            if (dt[q]) continue;
            int next=q+1;
            for (next=q+1;next<=n;next++)
            {
                if (!dt[next]) break;
            }
            if (next>n) break;
            if (cur[next]>cur[q])
            {
                dt[q]=true;
                smyrt=true;
                sb[q]=tm;
            }
        }
        if (!smyrt) break;
    }
    bool pr=true;
    for (int q=1;q<=n;q++)
    {
        if (sb[q]!=b[q]) pr=false;
    }
    if (pr)
    {
        perm spr(cur);
        ans.push_back(spr);
    }
}
int ind[MAXN];
int ind2[MAXN];
bool cmp(perm &a, perm &b){
    for (int q=1;q<=n;q++)
    {
        ind[a.ch[q]] = q;
        ind2[b.ch[q]] = q;
    }
    for (int q=1;q<=n;q++)
    {
        if (ind[q] < ind2[q]) return 1;
        if (ind[q] > ind2[q]) return 0;
    }
    return 0;
}
int main()
{
    cin>>n>>k;
    for (int q=1;q<=n;q++) cin>>b[q];
    for (int q=1;q<=n;q++) cur[q]=q;
    check();
    while (next_permutation(cur+1,cur+n+1)) check();
    sort(ans.begin(),ans.end(),cmp);
    if (k<ans.size()) ans[k-1].show();
    else cout<<"-1\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:81:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<perm>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     if (k<ans.size()) ans[k-1].show();
      |         ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 33 ms 316 KB Output is correct
3 Correct 383 ms 764 KB Output is correct
4 Correct 381 ms 280 KB Output is correct
5 Correct 422 ms 276 KB Output is correct
6 Correct 32 ms 212 KB Output is correct
7 Correct 393 ms 284 KB Output is correct
8 Correct 422 ms 272 KB Output is correct
9 Correct 40 ms 288 KB Output is correct
10 Correct 34 ms 212 KB Output is correct
11 Correct 4 ms 212 KB Output is correct
12 Correct 398 ms 464 KB Output is correct
13 Correct 389 ms 556 KB Output is correct
14 Correct 382 ms 332 KB Output is correct
15 Correct 382 ms 556 KB Output is correct
16 Correct 379 ms 368 KB Output is correct
17 Correct 376 ms 388 KB Output is correct
18 Correct 37 ms 324 KB Output is correct
19 Correct 422 ms 280 KB Output is correct
20 Correct 414 ms 280 KB Output is correct
21 Correct 381 ms 276 KB Output is correct
22 Correct 380 ms 280 KB Output is correct
23 Correct 389 ms 280 KB Output is correct
24 Correct 394 ms 280 KB Output is correct
25 Correct 380 ms 276 KB Output is correct
26 Correct 412 ms 276 KB Output is correct
27 Correct 390 ms 280 KB Output is correct
28 Correct 399 ms 280 KB Output is correct
29 Correct 371 ms 332 KB Output is correct
30 Correct 5 ms 212 KB Output is correct
31 Correct 4 ms 304 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
33 Correct 4 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 33 ms 316 KB Output is correct
3 Correct 383 ms 764 KB Output is correct
4 Correct 381 ms 280 KB Output is correct
5 Correct 422 ms 276 KB Output is correct
6 Correct 32 ms 212 KB Output is correct
7 Correct 393 ms 284 KB Output is correct
8 Correct 422 ms 272 KB Output is correct
9 Correct 40 ms 288 KB Output is correct
10 Correct 34 ms 212 KB Output is correct
11 Correct 4 ms 212 KB Output is correct
12 Correct 398 ms 464 KB Output is correct
13 Correct 389 ms 556 KB Output is correct
14 Correct 382 ms 332 KB Output is correct
15 Correct 382 ms 556 KB Output is correct
16 Correct 379 ms 368 KB Output is correct
17 Correct 376 ms 388 KB Output is correct
18 Correct 37 ms 324 KB Output is correct
19 Correct 422 ms 280 KB Output is correct
20 Correct 414 ms 280 KB Output is correct
21 Correct 381 ms 276 KB Output is correct
22 Correct 380 ms 280 KB Output is correct
23 Correct 389 ms 280 KB Output is correct
24 Correct 394 ms 280 KB Output is correct
25 Correct 380 ms 276 KB Output is correct
26 Correct 412 ms 276 KB Output is correct
27 Correct 390 ms 280 KB Output is correct
28 Correct 399 ms 280 KB Output is correct
29 Correct 371 ms 332 KB Output is correct
30 Correct 5 ms 212 KB Output is correct
31 Correct 4 ms 304 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
33 Correct 4 ms 300 KB Output is correct
34 Runtime error 1 ms 300 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 33 ms 316 KB Output is correct
3 Correct 383 ms 764 KB Output is correct
4 Correct 381 ms 280 KB Output is correct
5 Correct 422 ms 276 KB Output is correct
6 Correct 32 ms 212 KB Output is correct
7 Correct 393 ms 284 KB Output is correct
8 Correct 422 ms 272 KB Output is correct
9 Correct 40 ms 288 KB Output is correct
10 Correct 34 ms 212 KB Output is correct
11 Correct 4 ms 212 KB Output is correct
12 Correct 398 ms 464 KB Output is correct
13 Correct 389 ms 556 KB Output is correct
14 Correct 382 ms 332 KB Output is correct
15 Correct 382 ms 556 KB Output is correct
16 Correct 379 ms 368 KB Output is correct
17 Correct 376 ms 388 KB Output is correct
18 Correct 37 ms 324 KB Output is correct
19 Correct 422 ms 280 KB Output is correct
20 Correct 414 ms 280 KB Output is correct
21 Correct 381 ms 276 KB Output is correct
22 Correct 380 ms 280 KB Output is correct
23 Correct 389 ms 280 KB Output is correct
24 Correct 394 ms 280 KB Output is correct
25 Correct 380 ms 276 KB Output is correct
26 Correct 412 ms 276 KB Output is correct
27 Correct 390 ms 280 KB Output is correct
28 Correct 399 ms 280 KB Output is correct
29 Correct 371 ms 332 KB Output is correct
30 Correct 5 ms 212 KB Output is correct
31 Correct 4 ms 304 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
33 Correct 4 ms 300 KB Output is correct
34 Runtime error 1 ms 300 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -