File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ # pypy3
2+ # 시간(ms) : 152
3+ # 공간(KB) : 118540
4+ #
5+ # 공유 :
6+ # - gpt가 파이썬은 인덱스를 음수로 반복적으로 접근하면 내부적으로 인덱스 변환을 계속 해야 하므로 느리다함
7+ # 이 문제 기준으로는 8ms 차이라서 크게 신경 안써도 될듯 (백만 단위 이상 인덱싱에서 3~5% 정도 느리다고)
8+
9+ import sys
10+ input = sys .stdin .readline
11+
12+ n , h = map (int , input ().strip ().split ())
13+
14+ top = [0 ] * (h + 1 ) # 종유석
15+ bottom = [0 ] * (h + 1 ) # 석순
16+
17+ for _ in range (n // 2 ) : # 종유석, 석순 각각 같은 길이 카운팅
18+ bottom [int (input ())] += 1
19+ top [- int (input ())] += 1
20+
21+ for i in range (1 , h + 1 ) : # 종유석, 석순 각각 누적합을 통해 구간에 따른 hit 구하기
22+ top [i ] += top [i - 1 ]
23+ bottom [- (i + 1 )] += bottom [- i ]
24+
25+ min_hit = n # 최소 hit
26+ min_hit_cnt = 1 # 최소 hit 개수
27+ for i in range (1 , h + 1 ) :
28+ hit = top [i ] + bottom [i ] # 종유석, 석순 합쳐서 최종 hit 구하기
29+ if min_hit > hit :
30+ min_hit = hit
31+ min_hit_cnt = 1
32+ elif min_hit == hit :
33+ min_hit_cnt += 1
34+
35+ print (min_hit , min_hit_cnt )
36+
37+
You can’t perform that action at this time.
0 commit comments