CSES - Datatähti 2025 loppu - Results
Submission details
Task:Permutaatio
Sender:maweiyin24562
Submission time:2025-01-18 16:59:08 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#20.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.15 s1, 2, 3details
#6--1, 2, 3details
#7--1, 2, 3details
#8--1, 2, 3details
#9--1, 2, 3details
#100.01 s1, 2, 3details
#11--2, 3details
#12--2, 3details
#13--2, 3details
#14--2, 3details
#150.01 s2, 3details
#16--3details
#17--3details
#18--3details
#19--3details
#20--3details
#21--1, 2, 3details
#22--2, 3details
#23--3details

Code

#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N=200009;

int n;
int a[N],b[N];
int f[N],g[N];

int v[N];
bool flag;

void dfs(int u){
    if(flag)return;
    if(u==n+1){
        memset(f,0,sizeof(f));
        memset(g,0,sizeof(g));
        for(int i=1;i<=n;i++){
            f[i]=1;
            for(int j=1;j<i;j++){
                if(v[i]>v[j])f[i]=max(f[i],f[j]+1);
            }
        }
        for(int i=n;i>=1;i--){
            g[i]=1;
            for(int j=n;j>i;j--){
                if(v[i]>v[j])g[i]=max(g[i],g[j]+1);
            }
        }
        for(int i=1;i<=n;i++){
            if(a[i]!=f[i]||b[i]!=g[i])return;
        }
        flag=true;
        for(int i=1;i<n;i++){
            cout<<v[i]<<" ";
        }
        cout<<v[n]<<endl;
        return;
    }
    for(int i=1;i<=n;i++){
        v[u]=i;
        dfs(u+1);
    }
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    dfs(1);
    if(!flag)cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

/*
8
1 2 1 3 2 3 4 4
2 2 1 2 1 1 2 1
*/

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1
1
1

correct output

user output
1

Test 2

Group: 1, 2, 3

Verdict:

input
2
1 1
1 1

correct output
IMPOSSIBLE

user output
1 1

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 1 3
3 2 1

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 3 2
2 1 3

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
1 2 3 4 5
2 1 1 1 1

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Group: 1, 2, 3

Verdict:

input
8
1 2 2 3 2 3 4 5
1 3 2 2 1 1 1 1

correct output
1 8 5 7 2 3 4 6 

user output
(empty)

Test 7

Group: 1, 2, 3

Verdict:

input
8
1 2 2 2 1 3 2 1
3 5 4 3 2 3 2 1

correct output
3 8 6 5 2 7 4 1 

user output
(empty)

Test 8

Group: 1, 2, 3

Verdict:

input
8
1 2 3 4 5 6 7 8
1 1 1 1 1 1 1 1

correct output
1 2 3 4 5 6 7 8 

user output
(empty)

Test 9

Group: 1, 2, 3

Verdict:

input
8
1 1 1 1 1 1 1 1
8 7 6 5 4 3 2 1

correct output
8 7 6 5 4 3 2 1 

user output
(empty)

Test 10

Group: 1, 2, 3

Verdict:

input
8
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1

correct output
IMPOSSIBLE

user output
1 1 1 1 1 1 1 1

Test 11

Group: 2, 3

Verdict:

input
500
1 2 2 3 4 4 5 4 6 4 7 8 5 7 9 ...

correct output
25 205 54 76 500 218 316 181 3...

user output
(empty)

Test 12

Group: 2, 3

Verdict:

input
500
1 2 3 1 1 2 2 4 1 3 5 3 3 3 4 ...

correct output
336 388 404 309 233 377 240 42...

user output
(empty)

Test 13

Group: 2, 3

Verdict:

input
500
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 14

Group: 2, 3

Verdict:

input
500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
500 499 498 497 496 495 494 49...

user output
(empty)

Test 15

Group: 2, 3

Verdict:

input
500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 16

Group: 3

Verdict:

input
200000
1 2 2 3 2 1 3 3 2 4 2 3 5 4 5 ...

correct output
12162 165274 130162 168624 391...

user output
(empty)

Test 17

Group: 3

Verdict:

input
200000
1 1 2 3 3 2 4 3 4 5 2 5 6 7 3 ...

correct output
191389 13806 133836 173924 159...

user output
(empty)

Test 18

Group: 3

Verdict:

input
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 19

Group: 3

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
200000 199999 199998 199997 19...

user output
(empty)

Test 20

Group: 3

Verdict:

input
200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 21

Group: 1, 2, 3

Verdict:

input
8
1 1 2 1 2 3 1 3
4 3 3 2 2 3 1 1

correct output
IMPOSSIBLE

user output
(empty)

Test 22

Group: 2, 3

Verdict:

input
500
1 2 3 2 1 2 1 2 3 3 3 3 4 1 5 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 23

Group: 3

Verdict:

input
200000
1 1 1 2 2 3 1 3 4 1 5 4 2 5 6 ...

correct output
IMPOSSIBLE

user output
(empty)