아까 자존감 떨어진다고 했던 게이인데

12100번: 2048 (Easy) (acmicpc.net) 

12시부터 풀기 시작해서 조금전에 맞춤.

이 씻팔련아 내가 이긴거야.. 킥킥..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from collections import deque
import copy
 
 
def swiping(arr, dir):
    global n, res
 
    dxy = [[01], [10], [0-1], [-10]]
    for i in range(n):
        starts = [[i, 0], [0, i], [i, n-1], [n-1, i]]
        ind = starts[dir].copy()
        target = ind.copy()
        buff = deque()
        while True:
            if 0 <= ind[0< n and 0 <= ind[1< n:
                if arr[ind[0]][ind[1]] != 0:
                    val1 = arr[ind[0]][ind[1]]
                    if not buff:
                        buff.append([ind[0], ind[1], val1])
                    else:
                        x, y, val2 = buff.popleft()
                        arr[x][y] = 0
                        if val2 == val1:
                            arr[ind[0]][ind[1]] = 0
                            arr[target[0]][target[1]] = val2*2
                            if res < val2*2:
                                res = val2*2
                            target = [target[0]+dxy[dir]
                                      [0], target[1]+dxy[dir][1]]
                        else:
                            arr[target[0]][target[1]] = val2
                            if res < val2:
                                res = val2
                            target = [target[0]+dxy[dir]
                                      [0], target[1]+dxy[dir][1]]
                            buff.append([ind[0], ind[1], val1])
            ind = [ind[0]+dxy[dir][0], ind[1]+dxy[dir][1]]
            if ind[0< 0 or ind[0>= n or ind[1< 0 or ind[1>= n:
                if buff:
                    x, y, val2 = buff.popleft()
                    arr[x][y] = 0
                    arr[target[0]][target[1]] = val2
                break
 
 
def backtracking(k, li):
    if k == 5:
        return
    for dire in range(4):
        tmpArray = copy.deepcopy(li)
        swiping(tmpArray, dire)
        backtracking(k+1, tmpArray)
 
 
= int(input())
src = [list(map(int, input().split())) for _ in range(n)]
res = 0
for x in range(n):
    for y in range(n):
        if res < src[x][y]:
            res = src[x][y]
backtracking(0, src)
 
print(res)
 
cs

근데 이런거 코딩테스트때 나오면 걍 던져야되나..?