File tree Expand file tree Collapse file tree 3 files changed +105
-0
lines changed
Expand file tree Collapse file tree 3 files changed +105
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n = int (input ())
6+
7+ board = []
8+ for _ in range (n ):
9+ board .append (list (map (str , input ().rstrip ())))
10+
11+
12+ def counting ():
13+ max_cnt = 1
14+ for i in range (n ):
15+ cnt_row = cnt_col = 1
16+ for j in range (n - 1 ):
17+ # 가로
18+ if board [i ][j ] == board [i ][j + 1 ]: # 같은 색이면
19+ cnt_row += 1
20+ else :
21+ cnt_row = 1 # 다른 색이면 카운트 다시 시작
22+ max_cnt = max (max_cnt , cnt_row )
23+
24+ for j in range (n - 1 ):
25+ # 세로
26+ if board [j ][i ] == board [j + 1 ][i ]:
27+ cnt_col += 1
28+ else :
29+ cnt_col = 1
30+ max_cnt = max (max_cnt , cnt_col )
31+ return max_cnt
32+
33+ res = 1
34+ for i in range (n ):
35+ for j in range (n - 1 ):
36+ if n > j + 1 and board [i ][j ] != board [i ][j + 1 ]:
37+ # 아래와 교환
38+ board [i ][j ], board [i ][j + 1 ] = board [i ][j + 1 ], board [i ][j ]
39+ res = max (res , counting ())
40+ # 복구
41+ board [i ][j ], board [i ][j + 1 ] = board [i ][j + 1 ], board [i ][j ]
42+ if n > i + 1 and board [i ][j ] != board [i + 1 ][j ]:
43+ # 왼쪽과 교환
44+ board [i ][j ], board [i + 1 ][j ] = board [i + 1 ][j ], board [i ][j ]
45+ res = max (res , counting ())
46+ board [i ][j ], board [i + 1 ][j ] = board [i + 1 ][j ], board [i ][j ]
47+
48+ print (res )
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n = int (input ())
6+ schedule = [[0 , 0 ]]
7+ for _ in range (n ):
8+ schedule .append (list (map (int , input ().split ())))
9+
10+ profit = 0
11+
12+
13+ def find_max_profit (day , current_profit ):
14+ global profit
15+
16+ # n일 넘어가면 최대이익 갱신
17+ if day > n :
18+ profit = max (profit , current_profit )
19+ return
20+
21+ # 상담하지 않는 경우
22+ find_max_profit (day + 1 , current_profit )
23+
24+ if day + schedule [day ][0 ] - 1 <= n :
25+ find_max_profit (day + schedule [day ][0 ], current_profit + schedule [day ][1 ])
26+
27+
28+ find_max_profit (1 , 0 )
29+ print (profit )
30+
31+ """
32+ 7
33+ 3 10
34+ 5 20
35+ 1 10
36+ 1 20
37+ 2 15
38+ 4 40
39+ 2 200
40+ """
Original file line number Diff line number Diff line change 1+ def solution (s ):
2+ s = list (s .rstrip ())
3+ stack = []
4+
5+ for alpa in s :
6+ if stack :
7+ if stack [- 1 ] == alpa :
8+ stack .pop ()
9+ else :
10+ stack .append (alpa )
11+ else :
12+ stack .append (alpa )
13+
14+ if stack :
15+ return 0
16+ else :
17+ return 1
You can’t perform that action at this time.
0 commit comments