본문 바로가기
백준

큐빙 - 5373번

by 청원뿔세포 2022. 12. 8.

빡구현 문제이다.

시간복잡도 생각 안하고 가장 단순한 방식으로 노가다로 풀었다.

50%에서 자꾸 틀렸는데, 2일동안 답을 찾기 위해 디버깅해본 결과 출력 시 join을 안해주었다.

출력 양식에 띄어쓰기를 포함하지 않고 딱 붙여서 출력해야한다.

직접 테스트 해볼 때, 만들어둔 show2함수와 https://rubiks-cube-solver.com/ko/에서 비교해보며 오답을 찾아내었다.

모든 오류를 확인해볼수 있는 반례는 

1
12
F- R- U- B- L- D- F+ R+ U+ B+ L+ D+

이다.

모든 면을 전개도처럼 펼쳐서 일일이 확인해보면 어디서 틀렸는지 확인할 수 있다.

위 반례의 답은 직접 구해보길 바란다.

global up, front, right, left, back, down
up = [['w','w','w'],['w','w','w'],['w','w','w']]
front = [['r','r','r'],['r','r','r'],['r','r','r']]
right = [['b','b','b'],['b','b','b'],['b','b','b']]
left = [['g','g','g'],['g','g','g'],['g','g','g']]
back = [['o','o','o'],['o','o','o'],['o','o','o']]
down = [['y','y','y'],['y','y','y'],['y','y','y']]

def NotIntelligent(cmd):
    global up, front, right, left, back, down
    sideCopy = [['' for _ in range(3)] for j in range(3)]
    if cmd[0] == 'L':
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [left[2][i], left[1][i],left[0][i]]
                front[i][0], up[i][0], back[i][0], down[i][0] = up[i][0], back[i][0], down[i][0], front[i][0]
            left = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [left[0][2-i], left[1][2-i],left[2][2-i]]
                front[i][0], up[i][0], back[i][0], down[i][0] = down[i][0], front[i][0], up[i][0], back[i][0]
            left = sideCopy
    elif cmd[0] == 'R':
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [right[2][i], right[1][i],right[0][i]]
                front[i][2], up[i][2], back[i][2], down[i][2] = down[i][2], front[i][2], up[i][2], back[i][2]
            right = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [right[0][2-i], right[1][2-i],right[2][2-i]]
                front[i][2], up[i][2], back[i][2], down[i][2] = up[i][2], back[i][2], down[i][2], front[i][2]
            right = sideCopy
    elif cmd[0] == 'U':
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [up[2][i], up[1][i], up[0][i]]
                front[0][i], right[0][i], back[2][2-i], left[0][i] = right[0][i], back[2][2-i], left[0][i], front[0][i]
            up = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [up[0][2-i], up[1][2-i],up[2][2-i]]
                front[0][i], right[0][i], back[2][2-i], left[0][i] = left[0][i], front[0][i], right[0][i], back[2][2-i]
            up = sideCopy
    elif cmd[0] == 'D':
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [down[2][i], down[1][i], down[0][i]]
                front[2][i], right[2][i], back[0][2-i], left[2][i] = left[2][i], front[2][i], right[2][i], back[0][2-i] 
            down = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [down[0][2-i], down[1][2-i],down[2][2-i]]
                front[2][i], right[2][i], back[0][2-i], left[2][i] = right[2][i], back[0][2-i], left[2][i], front[2][i]
            down = sideCopy
    elif cmd[0] == 'F':
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [front[2][i], front[1][i], front[0][i]]
                down[0][i], right[2-i][0], up[2][2-i], left[i][2] = right[2-i][0], up[2][2-i], left[i][2], down[0][i]
            front = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [front[0][2-i], front[1][2-i],front[2][2-i]]
                down[0][i], right[2-i][0], up[2][2-i], left[i][2] = left[i][2], down[0][i], right[2-i][0], up[2][2-i]
            front = sideCopy
    else: # back
        if cmd[1] == '+':
            for i in range(3):
                sideCopy[i] = [back[2][i], back[1][i], back[0][i]]
                down[2][2-i], right[i][2], up[0][i], left[2-i][0] = left[2-i][0], down[2][2-i], right[i][2], up[0][i]
            back = sideCopy
        else:
            for i in range(3):
                sideCopy[i] = [back[0][2-i], back[1][2-i],back[2][2-i]]
                down[2][2-i], right[i][2], up[0][i], left[2-i][0] = right[i][2], up[0][i], left[2-i][0], down[2][2-i]
            back = sideCopy
def show():
    for i in up:
        print("".join(i))

# https://rubiks-cube-solver.com/ko/
def show2():
    for i in up:
        print('      ',end='')
        print(*i)
    for i in range(3):
        print(*left[i],end=' ')
        print(*front[i],end=' ')
        print(*right[i],end=' ')
        print(back[2-i][2],back[2-i][1],back[2-i][0])
    for i in down:
        print('      ',end='')
        print(*i)




def resetCube():
    global up, front, right, left, back, down
    up = [['w','w','w'],['w','w','w'],['w','w','w']]
    front = [['r','r','r'],['r','r','r'],['r','r','r']]
    right = [['b','b','b'],['b','b','b'],['b','b','b']]
    left = [['g','g','g'],['g','g','g'],['g','g','g']]
    back = [['o','o','o'],['o','o','o'],['o','o','o']]
    down = [['y','y','y'],['y','y','y'],['y','y','y']]


testCase = int(input())
for _ in range(testCase):
    cmds = int(input())
    inn = list(input().split())
    for cmd in inn:
        NotIntelligent(cmd)
        # print(cmd,'##############')
        # show2()

    show()
    resetCube()

 

'백준' 카테고리의 다른 글

평범한 배낭 - 12865번  (0) 2022.12.10
출제비 재분배 - 26145번  (0) 2022.12.10
Identify, Sort, Index, Solve - 26150번  (0) 2022.12.04
케빈 베이컨의 6단계 법칙 - 1389번  (0) 2022.11.30
경로 찾기 - 11403  (0) 2022.11.30

댓글