File tree 1 file changed +49
-0
lines changed 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ // http://boj.kr/4bfcd3c7db0441df9e6c8317af3672ab
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+
5
+ int dx[4 ] = {1 , 0 , -1 , 0 };
6
+ int dy[4 ] = {0 , 1 , 0 , -1 };
7
+
8
+ int d[505 ][505 ];
9
+ int board[505 ][505 ];
10
+ int n;
11
+
12
+ bool OOB (int i, int j){
13
+ return i < 0 || i >= n || j < 0 || j >= n;
14
+ }
15
+
16
+ int go (int x, int y){
17
+ if (d[x][y] != -1 )
18
+ return d[x][y];
19
+
20
+ d[x][y] = 1 ;
21
+ for (int dir = 0 ; dir < 4 ; dir++){
22
+ int nx = x + dx[dir];
23
+ int ny = y + dy[dir];
24
+ if (OOB (nx, ny) || board[x][y] >= board[nx][ny]) continue ;
25
+ d[x][y] = max (d[x][y], go (nx, ny) + 1 );
26
+ }
27
+ return d[x][y];
28
+ }
29
+
30
+ int main (void ) {
31
+ ios::sync_with_stdio (0 );
32
+ cin.tie (0 );
33
+
34
+ cin >> n;
35
+ for (int i = 0 ; i < n; i++){
36
+ for (int j = 0 ; j < n; j++){
37
+ cin >> board[i][j];
38
+ d[i][j] = -1 ;
39
+ }
40
+ }
41
+
42
+ int mx = 0 ;
43
+ for (int i = 0 ; i < n; i++){
44
+ for (int j = 0 ; j < n; j++)
45
+ mx = max (mx, go (i, j));
46
+ }
47
+
48
+ cout << mx << ' \n ' ;
49
+ }
You can’t perform that action at this time.
0 commit comments