File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+ input = sys .stdin .readline
3+
4+ n = int (input ())
5+ ary = []
6+ for _ in range (n ):
7+ ary .append (list (input ()))
8+ # print(ary)
9+ def check (a ):
10+ mcnt = 1
11+ for i in range (n ):
12+ cnt = 1
13+ for j in range (1 , n ):
14+ if a [i ][j - 1 ] == a [i ][j ]:
15+ cnt += 1
16+ else :
17+ cnt = 1
18+ mcnt = max (mcnt , cnt )
19+
20+ cnt = 1
21+ for j in range (1 , n ):
22+ if a [j - 1 ][i ] == a [j ][i ]:
23+ cnt += 1
24+ else :
25+ cnt = 1
26+ mcnt = max (mcnt , cnt )
27+
28+ return mcnt
29+ m = 0
30+ for i in range (n ):
31+ for j in range (n ):
32+ if i + 1 < n :
33+ ary [i ][j ], ary [i + 1 ][j ] = ary [i + 1 ][j ], ary [i ][j ]
34+ m = max (m , check (ary ))
35+ ary [i ][j ], ary [i + 1 ][j ] = ary [i + 1 ][j ], ary [i ][j ]
36+ if j + 1 < n :
37+ ary [i ][j ], ary [i ][j + 1 ] = ary [i ][j + 1 ], ary [i ][j ]
38+ m = max (m , check (ary ))
39+ ary [i ][j ], ary [i ][j + 1 ] = ary [i ][j + 1 ], ary [i ][j ]
40+
41+ print (m )
Original file line number Diff line number Diff line change 1+ n = int (input ())
2+
3+ ary = []
4+
5+ for _ in range (n ):
6+ a , b = map (int , input ().split ())
7+ ary .append ([a , b ])
8+
9+ dp = [0 ]* (n + 1 )
10+
11+ for i in range (n ):
12+ for j in range (i + ary [i ][0 ], n + 1 ):
13+ if dp [j ] < dp [i ] + ary [i ][1 ]:
14+ dp [j ] = dp [i ] + ary [i ][1 ]
15+ print (dp [- 1 ])
Original file line number Diff line number Diff line change 1+ def solution (s ):
2+ answer = 0
3+ s = list (s )
4+ stack = []
5+ for i in s :
6+ if len (stack ) == 0 :
7+ stack .append (i )
8+ elif i == stack [- 1 ]:
9+ stack .pop ()
10+ else :
11+ stack .append (i )
12+
13+ if len (stack ) == 0 :
14+ answer = 1
15+
16+ return answer
You can’t perform that action at this time.
0 commit comments