The Final Problem

0

0 votes
Medium
Problem

"Every fairy tale needs a good old-fashioned villain." -Moriarty

So finally you are here, at the center of the labyrinth. Are you even thinking about a way of getting out ?

Problem 9

Representation of a Rubik's Cube:

Yellow face is Up

Orange face is Front

Green face is Left

Blue face is Right

Red face is Back

White face is Down

Representation of a Rubik's Cube

Since the center pieces are fixed, any face rotation wont changes the central pieces.

Now lets take a look at the nomenclature of Rubik's Cube moves:

R= clockwise 90rotation of right face.

Ri=anti-clockwise 90rotation of right face.

Similarly rest of the moves are illustrated below:

enter image description here

Now you will be given the description of a scrambled Rubik's Cube, your task is to output the list of moves which will solve the Rubik's Cube.

For eg, if the given cube is:

enter image description here

It will be represented as following:

UP

GWYWYYRWW

FRONT

GGRBORYYY

LEFT

YOWRGOOOB

RIGHT

BGRGBBBOO

BACK

GROWRBBRG

DOWN

RBOYWGWYW

Let's say we apply the following moves to the cube:

B B

The move will rotate back face 180clockwise, now the cube is:

enter image description here

Input:

There will be 12 lines in input. First line will represent the face name, second line will represent the face color description, third line face name and so on. (see the example given in problem statement)

Output:

First line of output should contain an integer N denoting the number of moves.

Next line of output contains N space separated moves. (List of valid moves : R, Ri, L, Li, B, Bi, D, Di, F, Fi, U, Ui)

Scoring:

This is an approximation problem with relative scoring, you task is to maximize your score in comparison to other contestants.

Based on your output moves, the Rubik's cube given to you will be solved and score will be given.

Algorithm of score calculation:

score=0
for i=1 to 6:
    m=count of maximum occurring color on face i
    score+=m
    if m==9:
        score+=4              //bonus score for solving a face
if score==78:                 //cube solved
    score+=12                //bonus score for solving complete cube
    score+=200/N             //tie breaker for solved cubes, N=number of moves
Sample Input
UP
GWYWYYRWW
FRONT
GGRBORYYY
LEFT
YOWRGOOOB
RIGHT
BGRGBBBOO
BACK
GROWRBBRG
DOWN
RBOYWGWYW
Sample Output
2
R R
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?