1
1
// Authored by : HJPark
2
- // http://boj.kr/cc1b19ec95a54e04943a8204a5b34022
3
-
2
+ // Co-authored by : BaaaaaaaaaaarkingDog
3
+ // http://boj.kr/0b99159aaaba43379606d5aefce0b753
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
7
int n, m, k;
8
8
int board[22 ][22 ];
9
- int dxs [4 ] = {0 , 1 , 0 , -1 };
10
- int dys [4 ] = {1 , 0 , -1 , 0 };
9
+ int dx [4 ] = {0 , 1 , 0 , -1 };
10
+ int dy [4 ] = {1 , 0 , -1 , 0 };
11
11
int dir = 0 ; // 동 남 서 북
12
12
int cur_r = 1 , cur_c = 1 ; // 현 위치
13
13
int dice[6 ] = {1 , 2 , 3 , 4 , 5 , 6 };
14
14
int ans = 0 ;
15
15
16
- bool inbound (int r, int c) {
17
- if ((r > 0 ) && (r <= n) && (c > 0 ) && (c <= m))
18
- return true ;
19
- else
20
- return false ;
16
+ bool OOB (int r, int c) {
17
+ return r <= 0 || r > n || c <= 0 || c > m;
21
18
}
22
19
23
20
void next_dir () {
24
21
int dice_bottom = dice[5 ];
25
-
26
22
if (board[cur_r][cur_c] < dice_bottom)
27
23
dir = (dir + 1 ) % 4 ;
28
24
else if (board[cur_r][cur_c] > dice_bottom)
29
25
dir = (dir + 3 ) % 4 ;
30
- if (!inbound (cur_r + dxs[dir], cur_c + dys[dir]))
26
+
27
+ if (OOB (cur_r + dx[dir], cur_c + dy[dir]))
31
28
dir = (dir + 2 ) % 4 ;
32
29
}
33
30
34
<
8000
code>31 void get_score () {
35
32
int tile = 1 ;
36
- bool vis[22 ][22 ];
37
- fill (&vis[0 ][0 ], &vis[22 ][22 ], 0 );
33
+ bool vis[22 ][22 ] = {};
38
34
queue<pair<int , int >> q;
39
35
q.push ({cur_r, cur_c});
40
36
vis[cur_r][cur_c] = 1 ;
@@ -43,9 +39,9 @@ void get_score() {
43
39
pair<int , int > pos = q.front ();
44
40
q.pop ();
45
41
for (int i = 0 ; i < 4 ; i++) {
46
- int nxt_r = pos.first + dxs [i];
47
- int nxt_c = pos.second + dys [i];
48
- if (inbound (nxt_r, nxt_c) && !vis[nxt_r][nxt_c] && board[nxt_r][nxt_c] == board[cur_r][cur_c]) {
42
+ int nxt_r = pos.first + dx [i];
43
+ int nxt_c = pos.second + dy [i];
44
+ if (! OOB (nxt_r, nxt_c) && !vis[nxt_r][nxt_c] && board[nxt_r][nxt_c] == board[cur_r][cur_c]) {
49
45
q.push ({nxt_r, nxt_c});
50
46
vis[nxt_r][nxt_c] = 1 ;
51
47
tile++;
@@ -82,8 +78,8 @@ void move() {
82
78
dice[1 ] = tmp[0 ];
83
79
}
84
80
85
- cur_r += dxs [dir];
86
- cur_c += dys [dir];
81
+ cur_r += dx [dir];
82
+ cur_c += dy [dir];
87
83
}
88
84
89
85
int main (void ) {
0 commit comments