| Task: | Järjestys |
| Sender: | roni.juntunen |
| Submission time: | 2016-10-09 17:17:23 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | WRONG ANSWER | 0.14 s | 1 | details |
| #2 | WRONG ANSWER | 0.23 s | 2 | details |
| #3 | WRONG ANSWER | 0.97 s | 3 | details |
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());
}
}Test details
Test 1
Group: 1
Verdict: WRONG ANSWER
| 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 4 7 1 5 6 5 |
Test 2
Group: 2
Verdict: WRONG ANSWER
| input |
|---|
| 1000 650 716 982 41 133 1000 876 92... |
| correct output |
|---|
| 3984 207 207 206 207 128 127 126 12... |
| user output |
|---|
| 1000 65 328 76 478 737 281 696 989 ... |
Test 3
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 94703 47808 62366 31885 7091 8... |
| correct output |
|---|
| 399956 98676 98676 98675 98676 62994 ... |
| user output |
|---|
| 100008 9473 71577 78918 31721 4672 18... |
