CSES - Datatähti 2021 alku - Results
Submission details
Task:Arpakuutiot
Sender:iRobo
Submission time:2020-10-12 00:29:58 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.14 s1, 2details
#20.18 s1, 2details
#30.18 s1, 2details
#40.17 s1, 2details
#50.18 s1, 2details
#60.17 s1, 2details
#70.18 s1, 2details
#8ACCEPTED0.17 s1, 2details
#90.18 s1, 2details
#100.18 s1, 2details
#110.18 s2details
#120.18 s2details
#130.18 s2details
#140.18 s2details
#15ACCEPTED0.18 s2details
#160.18 s2details
#170.18 s2details
#180.18 s2details
#19ACCEPTED0.18 s2details
#200.18 s2details
#21ACCEPTED0.20 s2details
#220.20 s2details
#23ACCEPTED0.20 s2details
#240.20 s2details
#25ACCEPTED0.20 s2details
#26ACCEPTED0.20 s2details
#270.20 s2details
#280.20 s2details
#29ACCEPTED0.20 s2details
#300.20 s2details
#31ACCEPTED0.14 s1, 2details

Code

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

public class Main {

    static int[] tempCubeArray = new int[6];

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int cubeCount = input.nextInt();
        input.nextLine();

        int[][][] cubes = new int[cubeCount][5][5];
        int[][] cubeArray = new int[cubeCount][6];

        //get cubes from input into 2d arrays
        for(int i = 0; i < cubeCount; i++) {
            for(int j = 0; j < 5; j++) {
                String lineInput = input.nextLine();
                for(int k = 0; k < 5; k++) {
                    if(lineInput.charAt(k) == '.') {
                        cubes[i][j][k] = 0;
                    } else {
                        cubes[i][j][k] = Integer.parseInt(String.valueOf(lineInput.charAt(k)));
                    }
                }
            }
            input.nextLine();
        }

        for(int i = 0; i < cubeCount; i++) {
            for(int j = 0; j < 5; j++) {
                for(int k = 0; k < 5; k++) {
                    //System.out.print(cubes[i][j][k] + " ");
                }
                //System.out.println();
            }
            //System.out.println();
            //System.out.println();
        }

        for(int i = 0; i < cubeCount; i++) {
            int[] tempArray = convertCubeToArray(cubes[i]);
            for(int j = 0; j < 6; j++) {
                cubeArray[i][j] = tempArray[j];
            }
            if(cubeArray[i][3] == cubeArray[i][5]) { //weird bug fix?
                for(int k = 0; k < 6; k++) {
                    boolean check = true;
                    for(int m = 0; m < 6; m++) {
                        if(cubeArray[i][m] == k+1) {
                            check = false;
                        }
                    }
                    if(check) {
                        cubeArray[i][3] = k+1;
                    }
                }
            }
        }

        for(int i = 0; i < cubeArray.length; i++) {
            int[] tempArray = rotateCube(cubeArray[i]);
            for(int j = 0; j < 6; j++) {
                cubeArray[i][j] = tempArray[j];
            }
        }

        for(int i = 0; i < cubeCount; i++) {
            for(int j = 0; j < 6; j++) {
                //System.out.print(cubeArray[i][j] + " ");
            }
            //System.out.println(Arrays.toString(cubeArray[i]));
            //System.out.println();
        }

        //cubes then need to be rotated into the correct orientation! Smallest number up top

        sendOutput(cubeArray);

    }

    private static int[] rotateCube(int[] cubeArray) {
        int smallest = 100;

        for(int i = 0; i < 4; i++) {
            if(cubeArray[i+1] < smallest) {
                smallest = cubeArray[i+1];
            }
        }

        int slot = 0;
        for(int i = 0; i < 4; i++) {
            if(cubeArray[i+1] == smallest) {
                slot = i+1;
                break;
            }
        }

        int rotateLeft = slot - 1;

        for(int i = 0; i < rotateLeft; i++) {
            int temp = cubeArray[1];
            cubeArray[1] = cubeArray[2];
            cubeArray[2] = cubeArray[3];
            cubeArray[3] = cubeArray[4];
            cubeArray[4] = temp;
        }

        return cubeArray;
    }

    private static void sendOutput(int[][] cubeArray) {
        for(int i = 0; i < cubeArray.length; i++) {
            boolean test = true;
            for(int j = 0; j < cubeArray.length; j++) {
                if(Arrays.equals(cubeArray[i],cubeArray[j]) && i != j) {
                    System.out.print(j+1 + " ");
                    test = false;
                }
            }
            if(test) {
                System.out.print("-");
            }
            System.out.println();
        }
    }

    private static int[] convertCubeToArray(int[][] cube) {
        int[] cubeArray = new int[6];

        //find position of 1
        int x = 0, y = 0;
        for(int i = 0; i < 5; i++) {
            for(int j = 0; j < 5; j++) {
                if(cube[i][j] == 1) {
                    y = i;
                    x = j;
                }
            }
        }

        cubeArray[0] = 1;
        int[] previousTransforms = new int[5];
        Arrays.fill(tempCubeArray, 0);
        recursiveSolve(cube, y,x,1, cubeArray, previousTransforms, 0);
        cubeArray = tempCubeArray;

        return cubeArray;
    }

    private static void recursiveSolve(int[][] cube, int y, int x, int previous, int[] cubeArray, int[] previousTransforms, int depth) {
        boolean lastSlot = true;
        //check if there is a number above
        if(y-1 >= 0 && cube[y-1][x] != 0 && cube[y-1][x] != previous) {
            //System.out.println("transformUp");
            lastSlot = false;

            //create copies
            int[] cubeArray2 = cubeArray;
            int[] previousTransforms2 = previousTransforms;
            int depth2 = depth;

            cubeArray2[1] = cube[y-1][x];
            cubeArray2 = transformUp(cubeArray2);
            previousTransforms2[depth2] = 1;
            depth2++;
            recursiveSolve(cube,y-1,x,cube[y][x],cubeArray2,previousTransforms2,depth2);
        }
        //check if there is a number to the right
        if(x+1 < 5 && cube[y][x+1] != 0 && cube[y][x+1] != previous) {
            //System.out.println("transformRight");
            lastSlot = false;

            //create copies
            int[] cubeArray2 = cubeArray;
            int[] previousTransforms2 = previousTransforms;
            int depth2 = depth;

            cubeArray2[2] = cube[y][x+1];
            cubeArray2 = transformRight(cubeArray2);
            previousTransforms2[depth2] = 2;
            depth2++;
            recursiveSolve(cube,y,x+1,cube[y][x],cubeArray2,previousTransforms2,depth2);
        }
        //check if there is a number below
        if(y+1 < 5 && cube[y+1][x] != 0 && cube[y+1][x] != previous) {
            //System.out.println("transformDown");
            lastSlot = false;

            //create copies
            int[] cubeArray2 = cubeArray;
            int[] previousTransforms2 = previousTransforms;
            int depth2 = depth;

            cubeArray2[3] = cube[y+1][x];
            cubeArray2 = transformDown(cubeArray2);
            previousTransforms2[depth2] = 3;
            depth2++;
            recursiveSolve(cube,y+1,x,cube[y][x],cubeArray2,previousTransforms2,depth2);
        }
        //check if there is a number to the left
        if(x-1 >= 0 && cube[y][x-1] != 0 && cube[y][x-1] != previous) {
            //System.out.println("transformLeft");
            lastSlot = false;

            //create copies
            int[] cubeArray2 = cubeArray;
            int[] previousTransforms2 = previousTransforms;
            int depth2 = depth;

            cubeArray2[4] = cube[y][x-1];
            cubeArray2 = transformLeft(cubeArray2);
            previousTransforms2[depth2] = 4;
            depth2++;
            recursiveSolve(cube,y,x-1,cube[y][x],cubeArray2,previousTransforms2,depth2);
        }

        if(lastSlot) {
            int[] cubeArray2 = cubeArray;
            //reverse transformations to reach original cube rotation
            for(int i = depth-1; i >= 0; i--) {
                //System.out.println("anti-transforming " + previousTransforms[i]);
                if(previousTransforms[i] == 1) {
                    cubeArray2 = transformDown(cubeArray2);
                } else if(previousTransforms[i] == 2) {
                    cubeArray2 = transformLeft(cubeArray2);
                } else if(previousTransforms[i] == 3) {
                    cubeArray2 = transformUp(cubeArray2);
                } else if(previousTransforms[i] == 4) {
                    cubeArray2 = transformRight(cubeArray2);
                } else {
                    //System.out.println("error");
                }
            }
            //update the tempCubeArray with the new number positions on the cube, excluding 0 which is missing info
            for(int i = 0; i < 6; i++) {
                if(cubeArray2[i] != 0) {
                    if(tempCubeArray[i] == 0) {
                        tempCubeArray[i] = cubeArray2[i];
                    }
                }
            }
        }

    }

    private static int[] transformUp(int[] cube) {
        int temp = cube[0];
        cube[0] = cube[1];
        cube[1] = cube[5];
        cube[5] = cube[3];
        cube[3] = temp;
        return cube;
    }

    private static int[] transformRight(int[] cube) {
        int temp = cube[0];
        cube[0] = cube[2];
        cube[2] = cube[5];
        cube[5] = cube[4];
        cube[4] = temp;
        return cube;
    }

    private static int[] transformDown(int[] cube) {
        int temp = cube[0];
        cube[0] = cube[3];
        cube[3] = cube[5];
        cube[5] = cube[1];
        cube[1] = temp;
        return cube;
    }

    private static int[] transformLeft(int[] cube) {
        int temp = cube[0];
        cube[0] = cube[4];
        cube[4] = cube[5];
        cube[5] = cube[2];
        cube[2] = temp;
        return cube;
    }
}

Test details

Test 1

Group: 1, 2

Verdict:

input
3
165..
.4...
.3...
.2...
...

correct output
3
-
1

user output
-
-
-

Test 2

Group: 1, 2

Verdict:

input
5
264..
.5...
.3...
.1...
...

correct output
3
4 5
1
2 5
2 4

user output




-

Test 3

Group: 1, 2

Verdict:

input
5
152..
.4...
.3...
.6...
...

correct output
3 5
4
1 5
2
1 3

user output
3 5 
-
1 5 
-
1 3 

Test 4

Group: 1, 2

Verdict:

input
5
142..
.6...
.3...
.5...
...

correct output
4 5
3
2
1 5
1 4

user output

-
-

-

Test 5

Group: 1, 2

Verdict:

input
5
123..
.4...
.6...
.5...
...

correct output
3
4 5
1
2 5
2 4

user output




-

Test 6

Group: 1, 2

Verdict:

input
5
213..
.6...
.4...
.5...
...

correct output
4 5
3
2
1 5
1 4

user output
-


-
-

Test 7

Group: 1, 2

Verdict:

input
5
314..
.5...
.2...
.6...
...

correct output
3
4 5
1
2 5
2 4

user output

-



Test 8

Group: 1, 2

Verdict: ACCEPTED

input
5
163..
.2...
.5...
.4...
...

correct output
4 5
3
2
1 5
1 4

user output
4 5 


1 5 
1 4 

Test 9

Group: 1, 2

Verdict:

input
5
264..
.1...
.3...
.5...
...

correct output
2 3
1 3
1 2
5
4

user output
-


-
-

Test 10

Group: 1, 2

Verdict:

input
5
214..
.3...
.5...
.6...
...

correct output
5
3 4
2 4
2 3
1

user output

-



Test 11

Group: 2

Verdict:

input
10
.41..
.5...
.2...
36...
...

correct output
9
4 6 8
7 10
2 6 8
-
...

user output

4 6 8 
10 
2 6 8 
-
...

Test 12

Group: 2

Verdict:

input
10
5....
1436.
.2...
.....
...

correct output
5 8
6 10
4 7 9
3 7 9
1 8
...

user output
5 8 
6 10 
4 9 
3 9 
1 8 
...

Test 13

Group: 2

Verdict:

input
10
2....
41...
.63..
.5...
...

correct output
4 9 10
5 6 7 8
-
1 9 10
2 6 7 8
...

user output
4 9 
5 6 7 8 
-
1 9 
2 6 7 8 
...

Test 14

Group: 2

Verdict:

input
10
1....
634..
..52.
.....
...

correct output
2 3 4 5 6 9 10
1 3 4 5 6 9 10
1 2 4 5 6 9 10
1 2 3 5 6 9 10
1 2 3 4 6 9 10
...

user output
2 3 4 5 6 9 10 
1 3 4 5 6 9 10 
1 2 4 5 6 9 10 
1 2 3 5 6 9 10 
1 2 3 4 6 9 10 
...
Truncated

Test 15

Group: 2

Verdict: ACCEPTED

input
10
.2...
4516.
3....
.....
...

correct output
5 7 9 10
8
4 6
3 6
1 7 9 10
...

user output
5 7 9 10 

4 6 
3 6 
1 7 9 10 
...

Test 16

Group: 2

Verdict:

input
10
.56..
.2...
.4...
31...
...

correct output
4 9
3 5 10
2 5 10
1 9
2 3 10
...

user output
4 9 
5 10 
-
1 9 
2 10 
...

Test 17

Group: 2

Verdict:

input
10
..62.
.31..
45...
.....
...

correct output
2 3 4 8
1 3 4 8
1 2 4 8
1 2 3 8
6 7 9 10
...

user output
2 3 4 8 
1 3 4 8 
1 2 4 8 
1 2 3 8 
6 9 10 
...

Test 18

Group: 2

Verdict:

input
10
532..
.4...
.1...
.6...
...

correct output
3 8 9
5 6
1 8 9
7 10
2 6
...

user output
-

8 9 
7 10 
-
...

Test 19

Group: 2

Verdict: ACCEPTED

input
10
.64..
.1...
.3...
52...
...

correct output
2 5 6 7 8 9
1 5 6 7 8 9
4 10
3 10
1 2 6 7 8 9
...

user output
2 5 6 7 8 9 
1 5 6 7 8 9 
4 10 
3 10 
1 2 6 7 8 9 
...
Truncated

Test 20

Group: 2

Verdict:

input
10
.4...
326..
.1...
.5...
...

correct output
4 7 8
6 9 10
5
1 7 8
3
...

user output
4 7 8 
6 10 

1 7 8 

...

Test 21

Group: 2

Verdict: ACCEPTED

input
20
.6...
.4...
31...
.25..
...

correct output
3 7 11 16
6
1 7 11 16
5 19
4 19
...

user output
3 7 11 16 

1 7 11 16 
5 19 
4 19 
...
Truncated

Test 22

Group: 2

Verdict:

input
20
3....
5614.
..2..
.....
...

correct output
7 10 11 17 20
12
4 9 13 15 18
3 9 13 15 18
8 14 16
...

user output
7 10 17 20 
12 
4 9 13 15 18 
3 9 13 15 18 
8 14 16 
...
Truncated

Test 23

Group: 2

Verdict: ACCEPTED

input
20
42...
.316.
.5...
.....
...

correct output
5 12 13 15 18
16 20
6 8 14
9 19
1 12 13 15 18
...

user output
5 12 13 15 18 
16 20 
6 8 14 
9 19 
1 12 13 15 18 
...
Truncated

Test 24

Group: 2

Verdict:

input
20
..5..
.623.
41...
.....
...

correct output
2 6 11 12 13
1 6 11 12 13
5 16 18
7 14
3 16 18
...

user output
-
6 11 12 13 
5 16 18 
7 14 
3 16 18 
...
Truncated

Test 25

Group: 2

Verdict: ACCEPTED

input
20
.46..
53...
.1...
.2...
...

correct output
2 3 5 7 15 17 19
1 3 5 7 15 17 19
1 2 5 7 15 17 19
8 10 11 14
1 2 3 7 15 17 19
...

user output
2 3 5 7 15 17 19 
1 3 5 7 15 17 19 
1 2 5 7 15 17 19 
8 10 11 14 
1 2 3 7 15 17 19 
...
Truncated

Test 26

Group: 2

Verdict: ACCEPTED

input
20
.61..
.4...
35...
.2...
...

correct output
8 10 20
3 17 18 19
2 17 18 19
14 15
6 7 9 13
...

user output
8 10 20 
3 17 18 19 
2 17 18 19 
14 15 
6 7 9 13 
...
Truncated

Test 27

Group: 2

Verdict:

input
20
..2..
1463.
.5...
.....
...

correct output
2 3 5 6 9 20
1 3 5 6 9 20
1 2 5 6 9 20
11 19
1 2 3 6 9 20
...

user output
2 3 5 6 9 20 
1 3 5 6 9 20 
1 2 5 6 9 20 
11 19 
1 2 3 6 9 20 
...
Truncated

Test 28

Group: 2

Verdict:

input
20
...4.
5132.
6....
.....
...

correct output
2 8 10 12 13 19
1 8 10 12 13 19
4 5 15 16 17
3 5 15 16 17
3 4 15 16 17
...

user output
2 8 10 12 13 19 
1 8 10 12 13 19 
5 15 16 17 
-
3 15 16 17 
...
Truncated

Test 29

Group: 2

Verdict: ACCEPTED

input
20
.2...
.31..
45...
6....
...

correct output
5 8 9 14 17
3 10 16
2 10 16
13 15 19
1 8 9 14 17
...

user output
5 8 9 14 17 
3 10 16 
2 10 16 
13 15 19 
1 8 9 14 17 
...
Truncated

Test 30

Group: 2

Verdict:

input
20
3....
452..
.1...
.6...
...

correct output
3 7 8 9 14 15 16 19
4 12 13 17
1 7 8 9 14 15 16 19
2 12 13 17
11 20
...

user output
3 7 9 14 15 16 19 
4 12 13 17 
1 7 9 14 15 16 19 
2 12 13 17 
11 20 
...
Truncated

Test 31

Group: 1, 2

Verdict: ACCEPTED

input
2
546..
.3...
.2...
.1...
...

correct output
-
-

user output
-
-