-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2713.py
More file actions
56 lines (42 loc) · 1.52 KB
/
2713.py
File metadata and controls
56 lines (42 loc) · 1.52 KB
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
CODEC = {
' ': 0, 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13,
'N': 14, 'O': 15, 'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22, 'W': 23, 'X': 24, 'Y': 25, 'Z': 26
}
T = int(input())
for i in range(T):
line = input()
TC = [x for x in line.split()]
R, C = int(TC[0]), int(TC[1])
msg = ''.join(line.split('{0} {1} '.format(R, C)))
result = [[0 for j in range(C)] for k in range(R)]
binary = []
for alpha in msg:
binary += [int(x) for x in f'{CODEC[alpha]:05b}']
row, col = 0, 0
minR, minC, maxR, maxC = 0, 1, C-1, R-1
horizon, toggle_row, toggle_col = True, True, True
for bin in binary:
result[col][row] = bin
if horizon:
if (toggle_row and row==maxR) or (not toggle_row and row==minR):
if toggle_row:
maxR -= 1
else:
minR += 1
horizon = not horizon
toggle_row = not toggle_row
else:
if (toggle_col and col == maxC) or (not toggle_col and col == minC):
if toggle_col:
maxC -= 1
else:
minC += 1
horizon = not horizon
toggle_col = not toggle_col
if horizon:
row = row+1 if toggle_row else row-1
else:
col = col+1 if toggle_col else col-1
for j in result:
for k in j: print(k, end='')
print()