CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:roni.juntunen
Submission time:2016-10-09 17:30:50 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.14 s1details
#20.21 s2details
#31.07 s3details

Code

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author ronij
 */
public class Jarjestys {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int count = input.nextInt();
        int[] current = new int[count];
        int[] perfect = new int[count];
        int[] places = new int[count + 1];
        int change1;
        int change2;
        int pos;
        int[] out = new int[count * 5];
        int outplace = 0;
        boolean loop = true;
        for (int i = 0; i < count; i++) {
            current[i] = input.nextInt();
        }
        System.arraycopy(current, 0, perfect, 0, count);
        Arrays.sort(perfect);
        int lowest = perfect[0];
        for (int i = 0; i < count; i++) {
            places[perfect[i]] = i;
        }
        while(loop){
            if (current[0] != lowest){
                pos = places[current[0]];
                change1 = current[0];
                change2 = current[pos];
                current[0] = change2;
                current[pos] = change1;
                out[outplace] = pos + 1;
                outplace++;
            }
            else{
                loop = false;
                for (int i = 0; i < count; i++) {
                    if (current[i] != perfect[i]){
                        loop = true;
                        change1 = current[0];
                        change2 = current[i];
                        current[0] = change2;
                        current[i] = change1;
                        out[outplace] = i + 1;
                        outplace++;
                        break;
                    }
                }
            }
        }
        System.out.println(outplace);
        //String s = Arrays.toString(out).replaceAll(",","").replaceAll("0","");
        //System.out.println(s.substring(1, s.length() - 1).trim());
        for (int i = 0; i < outplace; i++) {
            System.out.println(out[i]);
        }
    }
}

Test details

Test 1

Group: 1

Verdict:

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
10
9
8
2
3
...

Test 2

Group: 2

Verdict:

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

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

user output
1000
650
328
760
478
...

Test 3

Group: 3

Verdict:

input
100000
94703 47808 62366 31885 7091 8...

correct output
399956
98676 98676 98675 98676 62994 ...

user output
100008
94703
71577
78918
31721
...