File tree Expand file tree Collapse file tree 4 files changed +62
-0
lines changed
백준 12015번 가장 긴 증가하는 부분 수열 2 v2 Expand file tree Collapse file tree 4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+
4
+ def solve ():
5
+ input = sys .stdin .readline
6
+ N = int (input ().strip ())
7
+ dts = list (map (int , input ().strip ().split ()))
8
+ LIS = [0 ]
9
+
10
+ for dt in dts :
11
+ if LIS [- 1 ] < dt :
12
+ LIS .append (dt )
13
+ else :
14
+ idx = binary_search (LIS , dt )
15
+ LIS [idx ] = dt
16
+
17
+ print (len (LIS ) - 1 )
18
+
19
+
20
+ def binary_search (LIS , dt ):
21
+ bgn , end = 0 , len (LIS ) - 1
22
+
23
+ while bgn <= end :
24
+ mid = (bgn + end ) // 2
25
+ if dt == LIS [mid ]:
26
+ return mid
27
+ elif dt < LIS [mid ]:
28
+ end = mid - 1
29
+ else : # dt > LIS[mid]
30
+ bgn = mid + 1
31
+
32
+ return bgn
33
+
34
+
35
+ if __name__ == '__main__' :
36
+ solve ()
Original file line number Diff line number Diff line change
1
+ 6
2
+ 10 20 10 30 20 50
Original file line number Diff line number Diff line change
1
+ 4
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from pathlib import Path
3
+ from unittest import TestCase
4
+ from main import solve
5
+
6
+
7
+ class Test (TestCase ):
8
+ def my_solve (self , testcase_input ):
9
+ sys .stdin = open (testcase_input , 'r' )
10
+ stdout = sys .stdout
11
+ sys .stdout = open ('stdout.txt' , 'w' )
12
+ solve ()
13
+ sys .stdout .close ()
14
+ sys .stdout = stdout
15
+
16
+ def test_solve (self , testcase_number : str ):
17
+ self .my_solve ('test' + testcase_number + '.txt' )
18
+ self .assertEqual (
19
+ Path ('test' + testcase_number + '_answer.txt' ).read_text ().strip (),
20
+ Path ('stdout.txt' ).read_text ().strip ())
21
+
22
+ def test1_solve (self ):
23
+ self .test_solve ('1' )
You can’t perform that action at this time.
0 commit comments