File tree Expand file tree Collapse file tree 1 file changed +106
-0
lines changed
Expand file tree Collapse file tree 1 file changed +106
-0
lines changed Original file line number Diff line number Diff line change 1+ # https://www.acmicpc.net/problem/15662
2+ # 톱니바퀴 (2), 골드5
3+
4+ import sys
5+ import copy
6+ from collections import deque , defaultdict
7+ from typing import List
8+ sys .stdin = open ('../../../input.txt' , 'r' )
9+
10+ T = int (input ())
11+ board = []
12+ board .append ([0 ] * 8 )
13+ for _ in range (T ):
14+ board .append (list (map (int ,str (input ()))))
15+
16+
17+ def print_2d_Arr (array ):
18+ for arr in array :
19+ print (arr )
20+
21+ # print("초기 보드 형태")
22+ # print_2d_Arr(board)
23+
24+
25+ K = int (input ()) # 총 회전 횟수
26+
27+ # 각 회전에 대해
28+ TIME_3 = 2
29+ TIME_9 = 6
30+
31+ def rotate (array ,dir ):
32+ length = len (array )
33+ # 시계방향 회전
34+ new_array = [0 ] * length
35+ if (dir == 1 ):
36+ for i in range (length ):
37+ if (i == 0 ):
38+ new_array [i ] = array [length - 1 ]
39+ else :
40+ new_array [i ] = array [i - 1 ]
41+
42+
43+ # 반시계방향 회전
44+ if (dir == - 1 ):
45+ for i in range (length ):
46+ if (i == length - 1 ):
47+ new_array [i ] = array [0 ]
48+ else :
49+ new_array [i ] = array [i + 1 ]
50+
51+ return new_array
52+
53+
54+ for _ in range (K ):
55+ start , dir = map (int ,input ().split (" " ))
56+
57+ directions = [0 ] * (T + 1 )
58+ directions [start ] = dir
59+
60+ # 아래 전파
61+ curr = start
62+ while True :
63+ next = curr + 1
64+ if next > T :
65+ break
66+
67+ # 회전 전파 조건
68+ if board [curr ][TIME_3 ] != board [next ][TIME_9 ]:
69+ directions [next ] = directions [curr ] * - 1
70+ curr = next
71+ else :
72+ break
73+
74+ # 위 전파
75+ curr = start
76+ while True :
77+ prev = curr - 1
78+ if prev < 1 :
79+ break
80+
81+ # 회전 전파 조건
82+ if board [curr ][TIME_9 ] != board [prev ][TIME_3 ]:
83+ directions [prev ] = directions [curr ] * - 1
84+ curr = prev
85+ else :
86+ break
87+
88+ # 회전
89+ # print("회전 방향")
90+ # print(directions)
91+
92+ for idx , dir in enumerate (directions ):
93+ if (dir != 0 ):
94+ board [idx ] = rotate (board [idx ],dir )
95+
96+
97+ # print("회전 후")
98+ # print_2d_Arr(board)
99+ # print()
100+
101+ # 12시 방향이 S극인 톱니바퀴의 개수 출력
102+ answer = 0
103+ for array in board :
104+ if array [0 ] == 1 :
105+ answer += 1
106+ print (answer )
You can’t perform that action at this time.
0 commit comments