-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12100.py
96 lines (89 loc) · 3.13 KB
/
12100.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
bit = [0, 0, 0, 0, 0]
max_num = 2
N = int(input())
mat = [list(map(int, input().split())) for _ in range(N)]
arr = [[] for _ in range(N)]
while bit[4] < 4:
for i in range(N):
arr[i] = mat[i][:]
for i in range(4):
if bit[i] == 4:
bit[i] -= 4
bit[i + 1] += 1
for move in range(5):
if bit[move] == 0:
for i in range(N):
for j in range(N):
if arr[i][j] == 0:
arr[i].pop(j)
arr[i].insert(0, 0)
for i in range(N):
for j in range(N-1, 0, -1):
if arr[i][j] == arr[i][j - 1] and arr[i][j] != 0:
arr[i][j] = arr[i][j] * 2
arr[i].pop(j-1)
arr[i].insert(0, 0)
#print('')
if bit[move] == 1:
for i in range(N):
for j in range(N-1, -1, -1):
if arr[i][j]== 0:
arr[i].pop(j)
arr[i].insert(N, 0)
#print("")
for i in range(N):
for j in range(N-1):
if arr[i][j] == arr[i][j + 1] and arr[i][j] != 0:
arr[i][j] = arr[i][j] * 2
arr[i].pop(j+1)
arr[i].insert(N, 0)
#print('')
if bit[move] == 2:
for i in range(N):
last = -1
pos = -1
for j in range(N):
if arr[j][i] != 0:
if arr[j][i] != last:
last = arr[j][i]
pos = j
elif arr[j][i] != 0:
arr[pos][i] = arr[pos][i] * 2
arr[j][i] = 0
last = -1
pos = -1
for i in range(N):
zeros = 0
for j in range(N):
if arr[j][i] == 0:
zeros += 1
else:
arr[j][i], arr[j - zeros][i] = arr[j - zeros][i], arr[j][i]
#print("")
if bit[move] == 3:
for i in range(N):
last = -1
pos = -1
for j in range(N-1, -1, -1):
if arr[j][i] != 0:
if arr[j][i] != last:
last = arr[j][i]
pos = j
elif arr[j][i] != 0:
arr[pos][i] = arr[pos][i] * 2
arr[j][i] = 0
last = -1
pos = -1
for i in range(N):
zeros = 0
for j in range(N-1, -1, -1):
if arr[j][i] == 0:
zeros += 1
else:
arr[j + zeros][i], arr[j][i] = arr[j][i], arr[j + zeros][i]
for i in range(N):
if max(arr[i]) > max_num:
max_num = max(arr[i])
print(bit,max_num)
bit[0] += 1
print(max_num)