๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 479

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 1976๋ฒˆ_์—ฌํ–‰ ๊ฐ€์ž

๋ฌธ์ œ https://www.acmicpc.net/problem/1976 1976๋ฒˆ: ์—ฌํ–‰ ๊ฐ€์ž ๋™ํ˜์ด๋Š” ์นœ๊ตฌ๋“ค๊ณผ ํ•จ๊ป˜ ์—ฌํ–‰์„ ๊ฐ€๋ ค๊ณ  ํ•œ๋‹ค. ํ•œ๊ตญ์—๋Š” ๋„์‹œ๊ฐ€ N๊ฐœ ์žˆ๊ณ  ์ž„์˜์˜ ๋‘ ๋„์‹œ ์‚ฌ์ด์— ๊ธธ์ด ์žˆ์„ ์ˆ˜๋„, ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค. ๋™ํ˜์ด์˜ ์—ฌํ–‰ ์ผ์ •์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด ์—ฌํ–‰ ๊ฒฝ๋กœ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ธ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1976๋ฒˆ ๋ฌธ์ œ - ์—ฌํ–‰ ๊ฐ€์ž import sys sys.setrecursionlimit(10 ** 6) # a๊ฐ€ ์†ํ•œ ์ง‘ํ•ฉ๊ณผ b๊ฐ€ ์†ํ•œ ์ง‘ํ•ฉ ํ•ฉ์น˜๊ธฐ def union(x, y): x = find(x) y = find(y) # a์™€ b์˜ ๋ถ€๋ชจ ๋…ธ๋“œ๊ฐ€ ๊ฐ™์œผ๋ฉด ๋™์ผํ•œ ์ง‘ํ•ฉ์ด๋ฏ€๋กœ ๋ฆฌํ„ด if x == y: return # ๋ถ€๋ชจ ๋…ธ๋“œ๊ฐ€ ๋‹ค๋ฅด๋‹ค๋ฉด ๋‘ ์ง‘ํ•ฉ์„ ํ•ฉ์นœ๋‹ค. else: parent..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 9935๋ฒˆ_๋ฌธ์ž์—ด ํญ๋ฐœ

๋ฌธ์ œ https://www.acmicpc.net/problem/9935 9935๋ฒˆ: ๋ฌธ์ž์—ด ํญ๋ฐœ ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋‘˜์งธ ์ค„์— ํญ๋ฐœ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ๊ธธ์ด๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 36๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋‘ ๋ฌธ์ž์—ด์€ ๋ชจ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 9935๋ฒˆ ๋ฌธ์ œ - ๋ฌธ์ž์—ด ํญ๋ฐœ import sys input = sys.stdin.readline # ์ž…๋ ฅ๊ฐ’ ์ฒ˜๋ฆฌ s = input().rstrip() bomb = input().rstrip() # stack์œผ๋กœ ๋ฌธ์ž์—ด ํญ๋ฐœ ๊ตฌํ˜„ stack = [] bomb_length = len(bomb) for char in s: stack.append(char) if ''..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 1806๋ฒˆ_๋ถ€๋ถ„ํ•ฉ

๋ฌธ์ œ https://www.acmicpc.net/problem/1806 1806๋ฒˆ: ๋ถ€๋ถ„ํ•ฉ ์ฒซ์งธ ์ค„์— N (10 ≤ N < 100,000)๊ณผ S (0 < S ≤ 100,000,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆ˜์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ˆ˜์—ด์˜ ๊ฐ ์›์†Œ๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์ ธ ์žˆ์œผ๋ฉฐ, 10,000์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1806๋ฒˆ ๋ฌธ์ œ - ๋ถ€๋ถ„ํ•ฉ import sys input = sys.stdin.readline n, s = map(int, input().split()) num = list(map(int, input().split())) target, left, right = 0, 0, 0 min_length = 1e9 while True: # print("left: ", lef..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver2] 11722๋ฒˆ_๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด

๋ฌธ์ œ https://www.acmicpc.net/problem/11722 11722๋ฒˆ: ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด ์ˆ˜์—ด A๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ˆ˜์—ด A = {10, 30, 10, 20, 20, 10} ์ธ ๊ฒฝ์šฐ์— ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์€ A = {10, 30, 10, 20, 20, 10} www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 11722๋ฒˆ ๋ฌธ์ œ - ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„์ˆ˜์—ด n = int(input()) arr = list(map(int, input().split())) dp = [1] * n for i in range(n): for j in range(1, i): if arr[i] < arr[j]: dp[i] = max(dp..

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

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

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 1744๋ฒˆ_์ˆ˜ ๋ฌถ๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/1744 1744๋ฒˆ: ์ˆ˜ ๋ฌถ๊ธฐ ๊ธธ์ด๊ฐ€ N์ธ ์ˆ˜์—ด์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ทธ ์ˆ˜์—ด์˜ ํ•ฉ์„ ๊ตฌํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ํ•˜์ง€๋งŒ, ๊ทธ๋ƒฅ ๊ทธ ์ˆ˜์—ด์˜ ํ•ฉ์„ ๋ชจ๋‘ ๋”ํ•ด์„œ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ์ˆ˜์—ด์˜ ๋‘ ์ˆ˜๋ฅผ ๋ฌถ์œผ๋ ค๊ณ  ํ•œ๋‹ค. ์–ด๋–ค ์ˆ˜๋ฅผ ๋ฌถ์œผ๋ ค๊ณ  ํ•  ๋•Œ, ์œ„์น˜์— www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1744๋ฒˆ ๋ฌธ์ œ - ์ˆ˜ ๋ฌถ๊ธฐ n = int(input()) minus_list = [] plus_list = [] one_list = [] answer = 0 for i in range(n): num = int(input()) if num 1: plus_list.append(num) else: one_list.append(num) plus_list.sort(reverse=Tr..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold2] 1202๋ฒˆ_๋ณด์„ ๋„๋‘‘

๋ฌธ์ œ https://www.acmicpc.net/problem/1202 1202๋ฒˆ: ๋ณด์„ ๋„๋‘‘ ์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N, K ≤ 300,000) ๋‹ค์Œ N๊ฐœ ์ค„์—๋Š” ๊ฐ ๋ณด์„์˜ ์ •๋ณด Mi์™€ Vi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 ≤ Mi, Vi ≤ 1,000,000) ๋‹ค์Œ K๊ฐœ ์ค„์—๋Š” ๊ฐ€๋ฐฉ์— ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ๋ฌด๊ฒŒ Ci๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ci www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1202๋ฒˆ ๋ฌธ์ œ - ๋ณด์„ ๋„๋‘‘ import sys, heapq input = sys.stdin.readline n, k = map(int, input().split()) jewelry = [list(map(int, input().split())) for _ in range(n)] bags = [int(input()) ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 1715๋ฒˆ_์นด๋“œ ์ •๋ ฌํ•˜๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/1715 1715๋ฒˆ: ์นด๋“œ ์ •๋ ฌํ•˜๊ธฐ ์ •๋ ฌ๋œ ๋‘ ๋ฌถ์Œ์˜ ์ˆซ์ž ์นด๋“œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์ž. ๊ฐ ๋ฌถ์Œ์˜ ์นด๋“œ์˜ ์ˆ˜๋ฅผ A, B๋ผ ํ•˜๋ฉด ๋ณดํ†ต ๋‘ ๋ฌถ์Œ์„ ํ•ฉ์ณ์„œ ํ•˜๋‚˜๋กœ ๋งŒ๋“œ๋Š” ๋ฐ์—๋Š” A+B ๋ฒˆ์˜ ๋น„๊ต๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผํ…Œ๋ฉด, 20์žฅ์˜ ์ˆซ์ž ์นด๋“œ ๋ฌถ์Œ๊ณผ 30์žฅ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1715๋ฒˆ ๋ฌธ์ œ - ์นด๋“œ ์ •๋ ฌํ•˜๊ธฐ import heapq import sys input = sys.stdin.readline n = int(input()) cards = [] result = 0 for i in range(n): heapq.heappush(cards, int(input())) if len(cards) == 1: print(0) else: while..