CSES - Datatähti Open 2021 - Results
Submission details
Task:Sorting
Sender:AMnu
Submission time:2021-01-30 01:08:02 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED36
#2ACCEPTED64
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.02 s2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.01 s1, 2details

Code

#include <bits/stdc++.h>
using namespace std;
int N, T;
int A[105];
map <int,bool> M;
void dfs() {
int x=0;
for (int i=0;i<N;i++) {
x*=10;
x+=A[i];
}
if (M[x]) return;
M[x]=1;
for (int i=3;i<N;i++) {
for (int j=1;j<i-1;j++) {
swap(A[j-1],A[i-1]);
swap(A[j],A[i]);
dfs();
swap(A[j-1],A[i-1]);
swap(A[j],A[i]);
}
}
}
int main() {
for (N=1;N<=5;N++) {
for (int i=0;i<N;i++) {
A[i]=i+1;
}
dfs();
}
cin>>T;
for (int i=1;i<=T;i++) {
cin>>N;
for (int j=1;j<=N;j++) {
cin>>A[j];
}
for (;N>5;N--) {
int x;
for (x=1;A[x]!=N;x++);
if (x==N) {
continue;
}
if (x==N-1) {
swap(A[N-4],A[N-3]);
swap(A[N-3],A[N-2]);
swap(A[N-2],A[N]);
swap(A[N-1],A[N]);
continue;
}
if (x==1) {
swap(A[1],A[3]);
swap(A[2],A[N-1]);
swap(A[3],A[N]);
swap(A[4],A[N-1]);
continue;
}
swap(A[x-1],A[N-1]);
swap(A[x],A[N]);
}
int x=0;
for (int j=1;j<=N;j++) {
x*=10;
x+=A[j];
}
if (M[x]) {
cout<<"YES\n";
}
else {
cout<<"NO\n";
}
}
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
153
1
1
2
1 2
...

correct output
YES
YES
NO
NO
NO
...

user output
YES
YES
NO
NO
NO
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
59
35 29 32 50 11 15 9 21 19 45 2...

correct output
YES
NO
YES
NO
YES
...

user output
YES
NO
YES
NO
YES
...
Truncated

Test 3

Group: 1, 2

Verdict: ACCEPTED

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

correct output
YES
NO
NO
NO
YES
...

user output
YES
NO
NO
NO
YES
...
Truncated

Test 4

Group: 1, 2

Verdict: ACCEPTED

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

correct output
NO
NO
YES
NO
YES
...

user output
NO
NO
YES
NO
YES
...
Truncated