๋ฌธ์
https://www.acmicpc.net/problem/1107
ํ์ด
# ๋ฐฑ์ค 1107๋ฒ ๋ฌธ์ - ๋ฆฌ๋ชจ์ปจ
import sys
input = sys.stdin.readline
target = int(input())
n = int(input())
broken = list(map(int, input().split()))
# ํ์ฌ ์ฑ๋์์ + ํน์ -๋ง ์ฌ์ฉํ์ฌ ์ด๋ํ๋ ๊ฒฝ์ฐ
cnt = abs(100 - target)
for nums in range(1000001):
nums = str(nums)
for i in range(len(nums)):
if int(nums[i]) in broken:
break
elif i == len(nums) - 1:
cnt = min(cnt, abs(int(nums) - target) + len(nums))
print(cnt)
ํน๋ณํ ์๊ณ ๋ฆฌ์ฆ์ด ์ฐ์ผ ๊ฒ ๊ฐ์ง๋ง ์์ ํ์์ผ๋ก ํ ์ ์๋ ๋ฌธ์ ์ด๋ค.
์ฌ๊ธฐ์ ์ฃผ์ํ ์ ์ ๋ฒ์๋ฅผ 50๋ง์ผ๋ก ์ก์ผ๋ฉด ์๋๋ค. ์ฑ๋์ด ๋ฌดํ๋ ์ด๋ฏ๋ก 100๋ง์์ ์ค์ด๋๋ ๊ฒ๋ ์๊ฐํด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋ฒ์์ ์ฃผ์ํด์ผ ํ๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 11478๋ฒ_์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ (0) | 2023.04.23 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 2512๋ฒ_์์ฐ (0) | 2023.04.22 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 9251๋ฒ_LCS (0) | 2023.04.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1011๋ฒ_Fly me to the Alpha Centauri (0) | 2023.04.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2447๋ฒ_๋ณ ์ฐ๊ธฐ - 10 (0) | 2023.04.21 |