CSES - Datatähti 2017 alku - Results
 Task: Järjestys Sender: planckcons Submission time: 2016-10-06 14:59:37 +0300 Language: Java Status: READY Result: 56
Feedback
groupverdictscore
#1ACCEPTED19
#2ACCEPTED37
#30
Test results
testverdicttimegroup
#1ACCEPTED0.14 s1details
#2ACCEPTED0.22 s2details
#3--3details

Code

```import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.ListIterator;

public class Jarjestys3 {

static int n;
static int c;
static List list;

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
int n = scan.nextInt();

int uno = 0;
list = new ArrayList();

for(int i = 0; i < n; i++)
{
int a = scan.nextInt();

if(a == 1)
uno = i + 1;
}

String fin = uno + " ";
reverse(list, uno);
for(int i = 2; i < n; i++)
{
fin += deleting(i);
}

fin += (n-1);
System.out.println((c+2) + " " + fin);
}

public static String deleting(int i)
{
int a = list.indexOf(i);
list.remove(a);
c += 2;
return (a + i - 2) + " " + (a + i - 1) + " ";
}

public static void reverse(List<?> l, int n)
{
ListIterator i1 = l.listIterator();
int pos1 = 1;
int pos2 = n;
ListIterator i2 = l.listIterator(pos2);
while (pos1 < pos2)
{
Object o1 = i1.next();
Object o2 = i2.previous();
i1.set(o2);
i2.set(o1);
++pos1;
--pos2;
}
}
}
```

Test details

Test 1

Group: 1

Verdict: ACCEPTED

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

correct output
32
10 10 9 10 9 8 7 9 4 2 1 4 5 2...

user output
18 10 2 3 8 9 8 9 6 7 7 8 8 9 ...

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
650 716 982 41 133 1000 876 92...

correct output
3984
207 207 206 207 128 127 126 12...

user output
1998 207 80 81 712 713 491 492...

Test 3

Group: 3

Verdict:

input
100000
94703 47808 62366 31885 7091 8...

correct output
399956
98676 98676 98675 98676 62994 ...

user output
(empty)