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

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] [์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ ๋ฌธ์ œ] 14888๋ฒˆ_์—ฐ์‚ฐ์ž ๋ผ์›Œ๋„ฃ๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/14888 14888๋ฒˆ: ์—ฐ์‚ฐ์ž ๋ผ์›Œ๋„ฃ๊ธฐ ์ฒซ์งธ ์ค„์— ์ˆ˜์˜ ๊ฐœ์ˆ˜ N(2 ≤ N ≤ 11)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” A1, A2, ..., AN์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ai ≤ 100) ์…‹์งธ ์ค„์—๋Š” ํ•ฉ์ด N-1์ธ 4๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋Š”๋ฐ, ์ฐจ๋ก€๋Œ€๋กœ ๋ง์…ˆ(+)์˜ ๊ฐœ์ˆ˜, ๋บ„์…ˆ(-)์˜ ๊ฐœ์ˆ˜, www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 14888๋ฒˆ ๋ฌธ์ œ - ์—ฐ์‚ฐ์ž ๋ผ์›Œ๋„ฃ๊ธฐ n = int(input()) number = list(map(int, input().split())) add, sub, mul, div = map(int, input().split()); max_result = - int(1e9) min_result = int(1e9) def dfs(..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 2293๋ฒˆ_๋™์ „2

๋ฌธ์ œ https://www.acmicpc.net/problem/2294 2294๋ฒˆ: ๋™์ „ 2 ์ฒซ์งธ ์ค„์— n, k๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n ≤ 100, 1 ≤ k ≤ 10,000) ๋‹ค์Œ n๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ๊ฐ์˜ ๋™์ „์˜ ๊ฐ€์น˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋™์ „์˜ ๊ฐ€์น˜๋Š” 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๊ฐ€์น˜๊ฐ€ ๊ฐ™์€ ๋™์ „์ด ์—ฌ๋Ÿฌ ๋ฒˆ ์ฃผ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2294๋ฒˆ ๋ฌธ์ œ - ๋™์ „ 2 n, k = map(int, input().split()) coins = [int(input()) for _ in range(n)] dp = [10001] * (k+1) dp[0] = 0 for coin in coins: for i in range(coin, k+1): dp[i] = min(dp[i], dp[i-coin..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 2293๋ฒˆ_๋™์ „1

๋ฌธ์ œ https://www.acmicpc.net/problem/2293 2293๋ฒˆ: ๋™์ „ 1 ์ฒซ์งธ ์ค„์— n, k๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n ≤ 100, 1 ≤ k ≤ 10,000) ๋‹ค์Œ n๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ๊ฐ์˜ ๋™์ „์˜ ๊ฐ€์น˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋™์ „์˜ ๊ฐ€์น˜๋Š” 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2293๋ฒˆ ๋ฌธ์ œ - ๋™์ „ 1 n, k = map(int, input().split()) coin = [int(input()) for _ in range(n)] dp = [0 for i in range(k+1)] dp[0] = 1 for i in coin: for j in range(i, k+1): if j - i >= 0: dp[j] += dp[j-i] print(dp[k])

โฌ› [Programmers] [BFS/DFS] [Python] Level3_๋„คํŠธ์›Œํฌ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/43162 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 3๋‹จ๊ณ„ - ๋„คํŠธ์›Œํฌ from collections import deque def bfs(graph, visited, n): if visited[n] == 1: return 0 q = deque() q.append((n)) visited[n] = 1 while q: v = q.popleft() for i in graph[v]: if not visited[i]: visite..

โฌ› [Programmers] [DP] [Python] Level3_์ •์ˆ˜ ์‚ผ๊ฐํ˜•

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/43105 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 3๋‹จ๊ณ„ - ์ •์ˆ˜ ์‚ผ๊ฐํ˜• def solution(triangle): answer = 0 dp = [[0]*i for i in range(1, len(triangle)+1)] dp[0][0] = triangle[0][0] dp[1][0] = dp[0][0] + triangle[1][0] dp[1][1] = dp[0][0] + triangle[1][1] for i in ran..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 14503๋ฒˆ_๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/14503 14503๋ฒˆ: ๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ ๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ฒญ์†Œํ•˜๋Š” ์˜์—ญ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ๊ฐ€ ์žˆ๋Š” ์žฅ์†Œ๋Š” N×M ํฌ๊ธฐ์˜ ์ง์‚ฌ๊ฐํ˜•์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, 1×1ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜• ์นธ์œผ๋กœ ๋‚˜๋ˆ„์–ด www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 14503๋ฒˆ ๋ฌธ์ œ - ๋กœ๋ด‡ ์ฒญ์†Œ๊ธฐ import sys from collections import deque input = sys.stdin.readline n,m = map(int,input().split()) visited = [[0] * m for _ in range(n)] r,c,d = map(int,input().split()) graph = [list(map(int,..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver4] 1269๋ฒˆ_๋Œ€์นญ ์ฐจ์ง‘ํ•ฉ

๋ฌธ์ œ https://www.acmicpc.net/problem/1269 1269๋ฒˆ: ๋Œ€์นญ ์ฐจ์ง‘ํ•ฉ ์ฒซ์งธ ์ค„์— ์ง‘ํ•ฉ A์˜ ์›์†Œ์˜ ๊ฐœ์ˆ˜์™€ ์ง‘ํ•ฉ B์˜ ์›์†Œ์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ง‘ํ•ฉ A์˜ ๋ชจ๋“  ์›์†Œ๊ฐ€, ์…‹์งธ ์ค„์—๋Š” ์ง‘ํ•ฉ B์˜ ๋ชจ๋“  ์›์†Œ๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ๊ฐ๊ฐ ์ฃผ์–ด www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1269๋ฒˆ ๋ฌธ์ œ - ๋Œ€์นญ ์ฐจ์ง‘ํ•ฉ a_cnt, b_cnt = map(int, input().split()) A = set(map(int, input().split())) B = set(map(int, input().split())) print(len(A^B))

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 1303๋ฒˆ_์ „์Ÿ-์ „ํˆฌ

๋ฌธ์ œ https://www.acmicpc.net/problem/1303 1303๋ฒˆ: ์ „์Ÿ - ์ „ํˆฌ ์ฒซ์งธ ์ค„์—๋Š” ์ „์Ÿํ„ฐ์˜ ๊ฐ€๋กœ ํฌ๊ธฐ N, ์„ธ๋กœ ํฌ๊ธฐ M(1 ≤ N, M ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ๋‹ค์Œ ๋‘ ๋ฒˆ์งธ ์ค„์—์„œ M+1๋ฒˆ์งธ ์ค„์—๋Š” ๊ฐ๊ฐ (X, Y)์— ์žˆ๋Š” ๋ณ‘์‚ฌ๋“ค์˜ ์˜ท์ƒ‰์ด ๋„์–ด์“ฐ๊ธฐ ์—†์ด ์ฃผ์–ด์ง„๋‹ค. ๋ชจ๋“  ์ž๋ฆฌ์—๋Š” www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1303๋ฒˆ ๋ฌธ์ œ - ์ „์Ÿ-์ „ํˆฌ from collections import deque dx, dy = [0,0,-1,1], [1,-1,0,0] n, m = map(int, input().split()) graph = [list(input()) for i in range(m)] visited = [[0]*n for j in range(m)] def bfs(..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 2504๋ฒˆ_๊ด„ํ˜ธ์˜ ๊ฐ’

๋ฌธ์ œ https://www.acmicpc.net/problem/2504 2504๋ฒˆ: ๊ด„ํ˜ธ์˜ ๊ฐ’ 4๊ฐœ์˜ ๊ธฐํ˜ธ ‘(’, ‘)’, ‘[’, ‘]’๋ฅผ ์ด์šฉํ•ด์„œ ๋งŒ๋“ค์–ด์ง€๋Š” ๊ด„ํ˜ธ์—ด ์ค‘์—์„œ ์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ์—ด์ด๋ž€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜๋œ๋‹ค. ํ•œ ์Œ์˜ ๊ด„ํ˜ธ๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ‘()’์™€ ‘[]’๋Š” ์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ์—ด์ด๋‹ค. ๋งŒ์ผ X www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2504๋ฒˆ ๋ฌธ์ œ - ๊ด„ํ˜ธ์˜ ๊ฐ’ bracket = list(input()) stack = [] answer = 0 tmp = 1 for i in range(len(bracket)): if bracket[i] == '(': stack.append(bracket[i]) tmp *= 2 elif bracket[i] == '[': stack.append(bracket[i]) tmp..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold5] 1068๋ฒˆ_ํŠธ๋ฆฌ

๋ฌธ์ œ https://www.acmicpc.net/problem/1068 1068๋ฒˆ: ํŠธ๋ฆฌ ์ฒซ์งธ ์ค„์— ํŠธ๋ฆฌ์˜ ๋…ธ๋“œ์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” 0๋ฒˆ ๋…ธ๋“œ๋ถ€ํ„ฐ N-1๋ฒˆ ๋…ธ๋“œ๊นŒ์ง€, ๊ฐ ๋…ธ๋“œ์˜ ๋ถ€๋ชจ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋งŒ์•ฝ ๋ถ€๋ชจ๊ฐ€ ์—†๋‹ค๋ฉด (๋ฃจํŠธ) -1์ด ์ฃผ์–ด์ง„๋‹ค www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1068๋ฒˆ ๋ฌธ์ œ - ํŠธ๋ฆฌ n = int(input()) node = list(map(int, input().split())) m = int(input()) cnt = 0 def dfs(n, node): node[n] = -2 for i in range(len(node)): if n == node[i]: dfs(i, node) dfs(m, node) for i in rang..