@@ -8,20 +8,22 @@ const val RIGHT = 5
8
8
const val LEFT = 1
9
9
10
10
class `acw톱니바퀴` {
11
+
11
12
var wheel = Array (4 ) { 0 }
12
13
var visit = Array (4 ) { false }
13
14
var turn = arrayListOf<Pair <Int , Int >>()
14
15
15
16
16
17
fun addTurn (w : Int , turnD : Int ) {
18
+ // dfs로 들어가면서 회전해야할 것들 turn에 추가해주기
17
19
18
20
19
21
var wheelNowRight = if (wheel[w] and (1 shl RIGHT ) != 0 ) 1 else 0
20
22
var wheelNowLeft = if (wheel[w] and (1 shl LEFT ) != 0 ) 1 else 0
21
- println (" $w $wheelNowLeft $wheelNowRight " )
22
23
23
- if (w - 1 > 0 ) {
24
+ if (w - 1 >= 0 ) {
24
25
val leftWheelsRight = if (wheel[w - 1 ] and (1 shl RIGHT ) != 0 ) 1 else 0
26
+
25
27
if (wheelNowLeft != leftWheelsRight && ! visit[w - 1 ]) {
26
28
visit[w - 1 ] = true
27
29
turn.add(Pair (w - 1 , turnD * - 1 ))
@@ -30,7 +32,7 @@ class `acw톱니바퀴` {
30
32
}
31
33
32
34
if (w + 1 < 4 ) {
33
- val rightWheelsLeft = if (wheel[w - 1 ] and (1 shl LEFT ) != 0 ) 1 else 0
35
+ val rightWheelsLeft = if (wheel[w + 1 ] and (1 shl LEFT ) != 0 ) 1 else 0
34
36
if (wheelNowRight != rightWheelsLeft && ! visit[w + 1 ]) {
35
37
visit[w + 1 ] = true
36
38
turn.add(Pair (w + 1 , turnD * - 1 ))
@@ -50,7 +52,7 @@ class `acw톱니바퀴` {
50
52
// 반시계
51
53
val last = wheel[w] and (1 shl 7 )
52
54
53
- wheel[w] = wheel[w] shl 1
55
+ wheel[w] = ( wheel[w] shl 1 ) and 255
54
56
if (last != 0 ) {
55
57
wheel[w]++
56
58
}
@@ -80,31 +82,27 @@ class `acw톱니바퀴` {
80
82
for (i in input) {
81
83
num + = (i.digitToInt() * m)
82
84
m / = 2
83
- }
85
+ }// 숫자로 바꿔서 저장
84
86
wheel[it] = num
85
87
86
88
}
87
89
88
90
val turnCnt = readln().toInt()
89
91
repeat(turnCnt) {
90
92
val (w, d) = readln().split(" " ).map { it.toInt() }
91
- turn.add(Pair (w, d))
92
- visit[w] = true
93
+ turn.add(Pair (w - 1 , d))
94
+ visit[w - 1 ] = true
93
95
94
96
95
- addTurn(w, d)
96
- println (turn)
97
- turnWheel()
98
- for (i in wheel) {
99
- println (i)
100
- }
101
- visit = Array (4 ) { false }
97
+ addTurn(w - 1 , d)// 회전해야할 것들 turn List에 추가해주기
98
+ turnWheel()// turn List에서 빼서 회전시켜주기
99
+ visit = Array (4 ) { false } // visit은 다시 사용해야함으로 다시 false로 초기화
102
100
}
103
101
104
102
105
103
var answer = 0
106
104
for (i in 0 until 4 ) {
107
- if ((wheel[i] and (1 shr 7 )) = = 0 ) {
105
+ if ((wheel[i] and (1 shl 7 )) ! = 0 ) {
108
106
answer + = (2.0 ).pow(i).toInt()
109
107
}
110
108
}
0 commit comments