Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 299ce1b

Browse files
committed
29210726
1 parent 9582579 commit 299ce1b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
h,w = map(int, input().split())
5+
arr = list(map(int, input().split()))
6+
ans = 0
7+
for i in range(w):
8+
max_left = max(arr[:i+1]) # ํ˜„์žฌ ๊ธฐ์ค€ ์™ผ์ชฝ์œผ๋กœ ๋†’์€ ๊ฑด๋ฌผ
9+
max_right = max(arr[i:]) # ํ˜„์žฌ ๊ธฐ์ค€ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋†’์€ ๊ฑด๋ฌผ
10+
stand = min(max_left, max_right) # ๋‘˜์ค‘ ์ž‘์€๊ฑฐ(์ž‘์€๊ฑฐ ๊ธฐ์ค€์œผ๋กœ ๋ฌผ์ด ์ฐธ)
11+
ans += stand-arr[i] # ๋น—๋ฌผ ์–‘ ๊ณ„์‚ฐ
12+
print(ans)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
from itertools import combinations
3+
input = sys.stdin.readline
4+
5+
def get_odd_cnt(string):
6+
cnt = 0
7+
for s in string:
8+
if int(s)%2==1:
9+
cnt += 1
10+
return cnt
11+
12+
def split_string(string,orig,_max):
13+
orig = _max # ๋ฐ‘์— for๋ฌธ์„ ๋Œ๋ฆด๋•Œ _max ๊ฐ’์„ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด ํ•œ ์ž๋ฆฌ ์ˆ˜์—์„œ ๋„˜์–ด์˜จ _max ๊ฐ’์— ๊ณ„์†ํ•ด์„œ ๋”ํ•ด์ค€๋‹ค.
14+
# EX) 999999 99 9 -> 1000107 -> .. ์ˆœ์œผ๋กœ ๊ฐˆ๋•Œ ์ „ ๋‹จ๊ณ„์—์„œ ๋„˜์–ด์˜จ _max ๊ฐ’์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
15+
if len(string) >2 :
16+
combs = combinations([x for x in range(1,len(string)+1)],2) # ๋ฌธ์ž์—ด์„ ์ž๋ฅผ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค.
17+
for a,b in combs: # ๊ฐ ๋ฌธ์ž์—ด ๋งˆ๋‹ค ํƒ์ƒ‰
18+
_max = orig
19+
s1 = string[:a]
20+
s2 = string[a:b]
21+
s3 = string[b:]
22+
if s3 == '': # 190 -> 1,9,0 or 19,0,'' ์ด ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋‹ค, ๋‘๋ฒˆ์จฐ ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•ด์คŒ
23+
continue
24+
_max += (get_odd_cnt(s1) + get_odd_cnt(s2) + get_odd_cnt(s3))
25+
new_string = str(int(s1)+int(s2)+int(s3))
26+
split_string(new_string,orig,_max)
27+
elif len(string) == 2:
28+
_max +=(get_odd_cnt(string[0]) + get_odd_cnt(string[1]))
29+
new_string = str(int(string[0])+int(string[1]))
30+
split_string(new_string,orig,_max)
31+
elif len(string) == 1:
32+
_max +=get_odd_cnt(string)
33+
max_list.append(_max)
34+
35+
string = input().rstrip()
36+
max_list = []
37+
split_string(string,0,0)
38+
print(min(max_list),max(max_list))

0 commit comments

Comments
ย (0)