๐Ÿ—๏ธ Algorithm 344

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 11054๋ฒˆ_๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด

๋ฌธ์ œ https://www.acmicpc.net/problem/11054 11054๋ฒˆ: ๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด ์ฒซ์งธ ์ค„์— ์ˆ˜์—ด A์˜ ํฌ๊ธฐ N์ด ์ฃผ์–ด์ง€๊ณ , ๋‘˜์งธ ์ค„์—๋Š” ์ˆ˜์—ด A๋ฅผ ์ด๋ฃจ๊ณ  ์žˆ๋Š” Ai๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 1,000, 1 ≤ Ai ≤ 1,000) www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 11054๋ฒˆ ๋ฌธ์ œ - ๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด n = int(input()) arr = list(map(int, input().split())) dp_increase = [1] * (n) dp_decrease = [1] * (n) for i in range(1, n): for j in range(i): if arr[i] > arr[j] and dp_increase[i] arr[j] and dp..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 14500๋ฒˆ_ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ

๋ฌธ์ œ https://www.acmicpc.net/problem/14500 14500๋ฒˆ: ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ํด๋ฆฌ์˜ค๋ฏธ๋…ธ๋ž€ ํฌ๊ธฐ๊ฐ€ 1×1์ธ ์ •์‚ฌ๊ฐํ˜•์„ ์—ฌ๋Ÿฌ ๊ฐœ ์ด์–ด์„œ ๋ถ™์ธ ๋„ํ˜•์ด๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•œ๋‹ค. ์ •์‚ฌ๊ฐํ˜•์€ ์„œ๋กœ ๊ฒน์น˜๋ฉด ์•ˆ ๋œ๋‹ค. ๋„ํ˜•์€ ๋ชจ๋‘ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ •์‚ฌ๊ฐํ˜•์˜ ๋ณ€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 14500๋ฒˆ ๋ฌธ์ œ - ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ import sys input = sys.stdin.readline def dfs(x, y, idx, total): global ans if ans >= total + max_val * (3 - idx): return if idx == 3: ans = max(ans, total) return else: for i in range(4): nx = ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver2] 1535๋ฒˆ_์•ˆ๋…•

๋ฌธ์ œ https://www.acmicpc.net/problem/1535 1535๋ฒˆ: ์•ˆ๋…• ์ฒซ์งธ ์ค„์— ์‚ฌ๋žŒ์˜ ์ˆ˜ N(≤ 20)์ด ๋“ค์–ด์˜จ๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๊ฐ๊ฐ์˜ ์‚ฌ๋žŒ์—๊ฒŒ ์ธ์‚ฌ๋ฅผ ํ•  ๋•Œ, ์žƒ๋Š” ์ฒด๋ ฅ์ด 1๋ฒˆ ์‚ฌ๋žŒ๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ๋“ค์–ด์˜ค๊ณ , ์…‹์งธ ์ค„์—๋Š” ๊ฐ๊ฐ์˜ ์‚ฌ๋žŒ์—๊ฒŒ ์ธ์‚ฌ๋ฅผ ํ•  ๋•Œ, ์–ป๋Š” ๊ธฐ์จ์ด 1๋ฒˆ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1535๋ฒˆ ๋ฌธ์ œ - ์•ˆ๋…• import sys input = sys.stdin.readline n = int(input()) stamina_consum = [0] + list(map(int, input().split())) get_pleasure = [0] + list(map(int, input().split())) dp = [[0] * 101 for _ in range(n +..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold3] 2252๋ฒˆ_์ค„ ์„ธ์šฐ๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/2252 2252๋ฒˆ: ์ค„ ์„ธ์šฐ๊ธฐ ์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 32,000), M(1 ≤ M ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. M์€ ํ‚ค๋ฅผ ๋น„๊ตํ•œ ํšŒ์ˆ˜์ด๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ํ‚ค๋ฅผ ๋น„๊ตํ•œ ๋‘ ํ•™์ƒ์˜ ๋ฒˆํ˜ธ A, B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋Š” ํ•™์ƒ A๊ฐ€ ํ•™์ƒ B์˜ ์•ž์— ์„œ์•ผ ํ•œ๋‹ค๋Š” ์˜ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2252๋ฒˆ ๋ฌธ์ œ - ์ค„ ์„ธ์šฐ๊ธฐ from collections import deque n, m = map(int, input().split()) graph = [[] for _ in range(n+1)] inDegree = [0] * (n+1) q = deque() answer = [] for _ in range(m): a, b = ma..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 2096๋ฒˆ_๋‚ด๋ ค๊ฐ€๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/2096 2096๋ฒˆ: ๋‚ด๋ ค๊ฐ€๊ธฐ ์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ์ˆซ์ž๊ฐ€ ์„ธ ๊ฐœ์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž๋Š” 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ์ค‘์˜ ํ•˜๋‚˜๊ฐ€ ๋œ๋‹ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2096๋ฒˆ ๋ฌธ์ œ - ๋‚ด๋ ค๊ฐ€๊ธฐ import sys input = sys.stdin.readline n = int(input()) arr = list(map(int, input().split())) maxDP = arr minDP = arr for _ in range(n-1): arr = list(map(int, input().split())) maxDP = [arr[0] + max(maxDP[..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 11057๋ฒˆ_์˜ค๋ฅด๋ง‰ ์ˆ˜

๋ฌธ์ œ https://www.acmicpc.net/problem/11057 11057๋ฒˆ: ์˜ค๋ฅด๋ง‰ ์ˆ˜ ์˜ค๋ฅด๋ง‰ ์ˆ˜๋Š” ์ˆ˜์˜ ์ž๋ฆฌ๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์„ ์ด๋ฃจ๋Š” ์ˆ˜๋ฅผ ๋งํ•œ๋‹ค. ์ด๋•Œ, ์ธ์ ‘ํ•œ ์ˆ˜๊ฐ€ ๊ฐ™์•„๋„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์นœ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, 2234์™€ 3678, 11119๋Š” ์˜ค๋ฅด๋ง‰ ์ˆ˜์ด์ง€๋งŒ, 2232, 3676, 91111์€ ์˜ค๋ฅด๋ง‰ ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋‹ค. ์ˆ˜ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 11057๋ฒˆ ๋ฌธ์ œ - ์˜ค๋ฅด๋ง‰ ์ˆ˜ n = int(input()) dp = [1]*10 for i in range(1,n) : for j in range(1,10) : dp[j] += dp[j-1] print(sum(dp)%10007) DP ๋ฌธ์ œ์ด๋‹ค. i ์ž๋ฆฌ ์ˆ˜ \ j 0์œผ๋กœ ๋๋‚˜๋Š” ์ˆซ์ž 1 2 3 4 5 n = 1 1 1 1 1 1 1 n =..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 17070๋ฒˆ_ํŒŒ์ดํ”„ ์˜ฎ๊ธฐ๊ธฐ 1

๋ฌธ์ œ https://www.acmicpc.net/problem/17070 17070๋ฒˆ: ํŒŒ์ดํ”„ ์˜ฎ๊ธฐ๊ธฐ 1 ์œ ํ˜„์ด๊ฐ€ ์ƒˆ ์ง‘์œผ๋กœ ์ด์‚ฌํ–ˆ๋‹ค. ์ƒˆ ์ง‘์˜ ํฌ๊ธฐ๋Š” N×N์˜ ๊ฒฉ์žํŒ์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๊ณ , 1×1ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜• ์นธ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ์นธ์€ (r, c)๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ r์€ ํ–‰์˜ ๋ฒˆํ˜ธ, c๋Š” ์—ด์˜ www.acmicpc.net ํ’€์ด import sys count = 0 N = int(input()) home = [] for _ in range(N): home.append([int(x) for x in sys.stdin.readline().rstrip().split()]) def dfs(x,y,state): # state 0: ๊ฐ€๋กœ, 1: ์„ธ๋กœ , 2: ๋Œ€๊ฐ์„  global count if x..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 2470๋ฒˆ_๋‘ ์šฉ์•ก

๋ฌธ์ œ https://www.acmicpc.net/problem/2470 2470๋ฒˆ: ๋‘ ์šฉ์•ก ์ฒซ์งธ ์ค„์—๋Š” ์ „์ฒด ์šฉ์•ก์˜ ์ˆ˜ N์ด ์ž…๋ ฅ๋œ๋‹ค. N์€ 2 ์ด์ƒ 100,000 ์ดํ•˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์šฉ์•ก์˜ ํŠน์„ฑ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” N๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ๋นˆ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. ์ด ์ˆ˜๋“ค์€ ๋ชจ๋‘ -1,000,000,000 ์ด์ƒ 1,000,00 www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2470๋ฒˆ ๋ฌธ์ œ - ๋‘ ์šฉ์•ก n = int(input()) arr = sorted(list(map(int, input().split()))) left = 0 right = n-1 answer = abs(arr[left] + arr[right]) check = [arr[left], arr[right]] while left < right: s = ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 2565๋ฒˆ_์ „๊นƒ์ค„

๋ฌธ์ œ https://www.acmicpc.net/problem/2565 2565๋ฒˆ: ์ „๊นƒ์ค„ ์ฒซ์งธ ์ค„์—๋Š” ๋‘ ์ „๋ด‡๋Œ€ ์‚ฌ์ด์˜ ์ „๊นƒ์ค„์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ „๊นƒ์ค„์˜ ๊ฐœ์ˆ˜๋Š” 100 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ „๊นƒ์ค„์ด A์ „๋ด‡๋Œ€์™€ ์—ฐ๊ฒฐ๋˜๋Š” ์œ„์น˜์˜ ๋ฒˆํ˜ธ์™€ B์ „๋ด‡๋Œ€์™€ ์—ฐ๊ฒฐ๋˜๋Š” www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2565๋ฒˆ ๋ฌธ์ œ - ์ „๊นƒ์ค„ n = int(input()) line = sorted([list(map(int, input().split())) for _ in range(n)]) dp = [1] * n for i in range(n): for j in range(i): if line[i][1] > line[j][1]: dp[i] = max(dp[i], dp[j] + 1) print(n ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold3] 2638๋ฒˆ_์น˜์ฆˆ

๋ฌธ์ œ https://www.acmicpc.net/problem/2638 2638๋ฒˆ: ์น˜์ฆˆ ์ฒซ์งธ ์ค„์—๋Š” ๋ชจ๋ˆˆ์ข…์ด์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋‘ ๊ฐœ์˜ ์ •์ˆ˜ N, M (5 ≤ N, M ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ๋ชจ๋ˆˆ์ข…์ด ์œ„์˜ ๊ฒฉ์ž์— ์น˜์ฆˆ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์€ 1๋กœ ํ‘œ์‹œ๋˜๊ณ , ์น˜์ฆˆ๊ฐ€ ์—†๋Š” ๋ถ€๋ถ„์€ 0์œผ๋กœ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2638๋ฒˆ ๋ฌธ์ œ - ์น˜์ฆˆ from collections import deque n, m = map(int, input().split()) graph = [list(map(int, input().split())) for _ in range(n)] dx, dy = [0,0,-1,1],[1,-1,0,0] def bfs(): q = deque() visited = [[0]..