QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373510#5199. Amazing TrickInfinityNS#TL 1ms4008kbC++141.3kb2024-04-01 19:33:312024-04-01 19:33:32

Judging History

你现在查看的是最新测评结果

  • [2024-04-01 19:33:32]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4008kb
  • [2024-04-01 19:33:31]
  • 提交

answer

#include<bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


void test(){
    int n;
    scanf("%i",&n);
    vector<int> a(n);
    vector<int> pos(n);
    for(int i=0;i<n;i++){
        scanf("%i",&a[i]);
        a[i]--;
        pos[a[i]]=i;
    }
    vector<int> perm(n);
    iota(all(perm),0);
    int bound=0;
    if(n<=2)bound=100;
    else bound=1e9;
    for(int i=0;i<bound;i++){
        shuffle(all(perm),rng);
        bool ok=1;
        for(int i=0;i<n;i++){
            if(perm[i]!=a[i]&&perm[i]!=i){

            }
            else{
                ok=0;
                break;
            }
        }
        if(!ok)continue;
        printf("Possible\n");
        vector<int> pos2(n);
        for(int i=0;i<n;i++){
            pos2[perm[i]]=i;
        }
        for(int i=0;i<n;i++){
            printf("%i ",pos[perm[i]]+1);
        }
        printf("\n");
        for(int i=0;i<n;i++){
            printf("%i ",pos2[i]+1);
        }
        printf("\n");
        return;
    }
    printf("Impossible\n");
}
int main(){
    int t;
    scanf("%i",&t);
    while(t--){
        test();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3792kb

input:

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

output:

Impossible
Possible
2 3 1 
3 1 2 
Possible
3 4 2 1 
3 4 2 1 
Possible
3 1 4 5 2 
5 3 4 1 2 

result:

ok 3/4 are 'Possible' (4 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 4008kb

input:

50
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

output:

Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Imp...

result:

ok 0/50 are 'Possible' (50 test cases)

Test #3:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

25
2
2 1
2
2 1
2
2 1
2
1 2
2
2 1
2
1 2
2
1 2
2
1 2
2
1 2
2
1 2
2
2 1
2
2 1
2
1 2
2
1 2
2
2 1
2
2 1
2
2 1
2
1 2
2
1 2
2
1 2
2
2 1
2
2 1
2
2 1
2
2 1
2
2 1

output:

Impossible
Impossible
Impossible
Possible
2 1 
2 1 
Impossible
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Impossible
Impossible
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Impossible
Impossible
Impossible
Possible
2 1 
2 1 
Possible
2 1 
2 1 
Possible
2 ...

result:

ok 11/25 are 'Possible' (25 test cases)

Test #4:

score: -100
Time Limit Exceeded

input:

16
3
3 2 1
3
3 1 2
3
3 1 2
3
2 3 1
3
3 1 2
3
2 1 3
3
2 3 1
3
3 2 1
3
3 1 2
3
2 1 3
3
1 2 3
3
1 3 2
3
3 1 2
3
3 1 2
3
3 2 1
3
2 1 3

output:


result: