๐Ÿค–/๋ฐฑ์ค€ 109

๋ฐฑ์ค€ 10816: ์ˆซ์ž ์นด๋“œ 2 (Python)

https://www.acmicpc.net/problem/10816 10816๋ฒˆ: ์ˆซ์ž ์นด๋“œ 2 ์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10, www.acmicpc.net ์ฑ„์ ํ•˜๋Š”๋ฐ๋งŒ 1๋ถ„ 30์ดˆ๋Š” ๊ฑธ๋ ค์„œ ๋‚˜ ์ฒ˜์Œ์— ์‹œ๊ฐ„ ์ดˆ๊ณผ ๋œจ๋Š” ์ค„^^,, import sys n = int(input()) card = sorted(map(int, sys.stdin.readline().split())) m = int(input()) find = list(map(int, sys.stdin.readline().split())) dict_card = d..

๋ฐฑ์ค€ 1920: ์ˆ˜ ์ฐพ๊ธฐ (Python)

https://www.acmicpc.net/problem/1920 1920๋ฒˆ: ์ˆ˜ ์ฐพ๊ธฐ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ N(1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” N๊ฐœ์˜ ์ •์ˆ˜ A[1], A[2], …, A[N]์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” M(1 ≤ M ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” M๊ฐœ์˜ ์ˆ˜๋“ค์ด ์ฃผ์–ด์ง€๋Š”๋ฐ, ์ด ์ˆ˜๋“ค www.acmicpc.net ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ์ด์ง„ํƒ์ƒ‰์„ ํ’€์–ด์ฃผ์—ˆ๋‹ค import sys n = int(sys.stdin.readline().rstrip()) a = list(map(int, sys.stdin.readline().split())) m = int(sys.stdin.readline().rstrip()) b = list(map(int, sys.stdin.readline().s..

๋ฐฑ์ค€ 1707: ์ด๋ถ„๊ทธ๋ž˜ํ”„ (Python)

https://www.acmicpc.net/problem/1707 1707๋ฒˆ: ์ด๋ถ„ ๊ทธ๋ž˜ํ”„ ์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š”๋ฐ, ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์งธ ์ค„์—๋Š” ๊ทธ๋ž˜ํ”„์˜ ์ •์ ์˜ ๊ฐœ์ˆ˜ V์™€ ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ E๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— www.acmicpc.net ๋‚  ์•„์ฃผ์•„์ฃผ์•„์ฃผ์•„์ฃผ ํ™”๋‚˜๊ฒŒ ํ•œ ๋ฌธ์ œ๋‹ค ๋งž๋Š” ๊ฑฐ ๊ฐ™์€๋ฐ ์ž๊พธ ํ‹€๋ ค์„œ ์—ด์‹ฌํžˆ ๋ฐ˜๋ก€ ์ฐพ๊ณ  ๋‹ค๋…”๋‹ค ์˜ˆ์‹œ ์ž…๋ ฅ1 2 3 2 1 3 2 3 4 4 1 2 2 3 3 4 4 2 ์˜ˆ์‹œ ์ถœ๋ ฅ1 YES NO ์˜ˆ์‹œ ์ž…๋ ฅ2 11 3 1 2 3 3 2 1 3 2 3 4 4 1 2 2 3 3 4 4 2 3 2 2 1 3 2 4 4 2 1 3 2 4 3 4 1 5 2 1 5 1 2 5 2 1 2 2 5 4 3 1 2 4 3..

๋ฐฑ์ค€ 7564: ๋‚˜์ดํŠธ์˜ ์ด๋™ (Python)

https://www.acmicpc.net/problem/7562 7562๋ฒˆ: ๋‚˜์ดํŠธ์˜ ์ด๋™ ์ฒด์ŠคํŒ ์œ„์— ํ•œ ๋‚˜์ดํŠธ๊ฐ€ ๋†“์—ฌ์ ธ ์žˆ๋‹ค. ๋‚˜์ดํŠธ๊ฐ€ ํ•œ ๋ฒˆ์— ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ์นธ์€ ์•„๋ž˜ ๊ทธ๋ฆผ์— ๋‚˜์™€์žˆ๋‹ค. ๋‚˜์ดํŠธ๊ฐ€ ์ด๋™ํ•˜๋ ค๊ณ  ํ•˜๋Š” ์นธ์ด ์ฃผ์–ด์ง„๋‹ค. ๋‚˜์ดํŠธ๋Š” ๋ช‡ ๋ฒˆ ์›€์ง์ด๋ฉด ์ด ์นธ์œผ๋กœ ์ด๋™ํ•  ์ˆ˜ www.acmicpc.net from collections import deque t = int(input()) def bfs(x1, y1, x2, y2): queue = deque() queue.append([x1, y1]) chess[x1][y1] = 1 dx = [-1, -2, -2, -1, 1, 2, 2, 1] dy = [-2, -1, 1, 2, 2, 1, -1, -2] while queue: qx, qy = queue..

๋ฐฑ์ค€ 2606: ๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ (Python)

https://www.acmicpc.net/problem/2206 2206๋ฒˆ: ๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ N×M์˜ ํ–‰๋ ฌ๋กœ ํ‘œํ˜„๋˜๋Š” ๋งต์ด ์žˆ๋‹ค. ๋งต์—์„œ 0์€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ด๊ณ , 1์€ ์ด๋™ํ•  ์ˆ˜ ์—†๋Š” ๋ฒฝ์ด ์žˆ๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋‹น์‹ ์€ (1, 1)์—์„œ (N, M)์˜ ์œ„์น˜๊นŒ์ง€ ์ด๋™ํ•˜๋ ค ํ•˜๋Š”๋ฐ, ์ด๋•Œ ์ตœ๋‹จ ๊ฒฝ๋กœ www.acmicpc.net from collections import deque n, m = map(int, input().split()) list = [[] for _ in range(n)] for i in range(n): data = input() for j in range(m): list[i].append(int(data[j])) def bfs(x, y, z): dx = [1, -1, 0, ..

๋ฐฑ์ค€ 1697: ์ˆจ๋ฐ”๊ผญ์งˆ (Python)

https://www.acmicpc.net/problem/1697 1697๋ฒˆ: ์ˆจ๋ฐ”๊ผญ์งˆ ์ˆ˜๋นˆ์ด๋Š” ๋™์ƒ๊ณผ ์ˆจ๋ฐ”๊ผญ์งˆ์„ ํ•˜๊ณ  ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ํ˜„์žฌ ์  N(0 ≤ N ≤ 100,000)์— ์žˆ๊ณ , ๋™์ƒ์€ ์  K(0 ≤ K ≤ 100,000)์— ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ๊ฑท๊ฑฐ๋‚˜ ์ˆœ๊ฐ„์ด๋™์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜๊ฐ€ X์ผ www.acmicpc.net from collections import deque MAX = 100000 n, k = map(int, input().split()) queue = deque() queue.append(n) visited = [0] * (MAX + 1) while queue: q = queue.popleft() mv = [q + 1, q - 1, 2 * q] if q == k: pri..

๋ฐฑ์ค€ 7569: ํ† ๋งˆํ†  (Python)

https://www.acmicpc.net/problem/7569 7569๋ฒˆ: ํ† ๋งˆํ†  ์ฒซ ์ค„์—๋Š” ์ƒ์ž์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋‘ ์ •์ˆ˜ M,N๊ณผ ์Œ“์•„์˜ฌ๋ ค์ง€๋Š” ์ƒ์ž์˜ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” H๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. M์€ ์ƒ์ž์˜ ๊ฐ€๋กœ ์นธ์˜ ์ˆ˜, N์€ ์ƒ์ž์˜ ์„ธ๋กœ ์นธ์˜ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋‹จ, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100, www.acmicpc.net 7576๋ฒˆ ๋ฌธ์ œ์˜ 3์ฐจ์› ๋ฒ„์ „์ด๋‹ค 3์ฐจ์›์ด๋ผ๋Š” ๊ฒƒ๋งŒ ์‹ ๊ฒฝ ์จ์ฃผ๊ณ  ๋˜‘๊ฐ™์ด ํ’€๋ฉด ๋œ๋‹ค pypy3๋กœ ์ œ์ถœํ•จ from collections import deque m, n, h = map(int, input().split()) tomato = [[] for _ in range(h)] for i in range(h): for j in range(n): data = list(map(i..

๋ฐฑ์ค€ 7576: ํ† ๋งˆํ†  (Python)

https://www.acmicpc.net/problem/7576 7576๋ฒˆ: ํ† ๋งˆํ†  ์ฒซ ์ค„์—๋Š” ์ƒ์ž์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋‘ ์ •์ˆ˜ M,N์ด ์ฃผ์–ด์ง„๋‹ค. M์€ ์ƒ์ž์˜ ๊ฐ€๋กœ ์นธ์˜ ์ˆ˜, N์€ ์ƒ์ž์˜ ์„ธ๋กœ ์นธ์˜ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋‹จ, 2 ≤ M,N ≤ 1,000 ์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ๋Š” ํ•˜๋‚˜์˜ ์ƒ์ž์— ์ €์žฅ๋œ ํ† ๋งˆํ†  www.acmicpc.net ๋ฏธ๋กœ ์ฐพ๊ธฐ๋ž‘ ๋น„์Šทํ•œ ๋ฌธ์ œ๋‹ค ์ฒ˜์Œ์—” BFS๋ฅผ ๋™์‹œ์— ๋Œ๋ ค์•ผ ํ•˜๋‚˜.....? ํ•˜๊ณ  ํ˜ผ์ž ์—„์ฒญ ๊ณ ๋ฏผํ–ˆ๋Š”๋ฐ ๊ทธ๋ƒฅ ํ์— ์žˆ๋Š” ๊ฑธ ์ „๋ถ€ ๋Œ๋ฆฌ๊ธฐ๋งŒ ํ•ด๋„ ๋œ๋‹ค๋Š” ๊ฑธ ๊นจ๋‹ฌ์Œ ๋งจ ๋งˆ์ง€๋ง‰ ์ขŒํ‘œ์—์„œ ๋๋‚˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐ๊ณผ๊ฐ’์€ ์ตœ๋Œ€๊ฐ’! ์ฒ˜์Œ ์‹œ์ž‘์„ 1๋กœ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐ๊ณผ๊ฐ’์€ -1 ํ•ด์ฃผ๊ธฐ! from collections import deque m, n = map(int, input().split(..

๋ฐฑ์ค€ 2178: ๋ฏธ๋กœ ํƒ์ƒ‰ (Python)

https://www.acmicpc.net/problem/2178 2178๋ฒˆ: ๋ฏธ๋กœ ํƒ์ƒ‰ ์ฒซ์งธ ์ค„์— ๋‘ ์ •์ˆ˜ N, M(2 ≤ N, M ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” M๊ฐœ์˜ ์ •์ˆ˜๋กœ ๋ฏธ๋กœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ๊ฐ์˜ ์ˆ˜๋“ค์€ ๋ถ™์–ด์„œ ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ์ด์ฝ”ํ…Œ ๊ต์žฌ์— ์žˆ๋˜ ๋ฌธ์ œ์ด๊ธฐ๋„ ํ•˜๊ณ  ์–ด๋Š ์ •๋„ ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰ ๋ฌธ์ œ์— ์ต์ˆ™ํ•ด์ ธ์„œ ๋น ๋ฅด๊ฒŒ ํ’€์—ˆ๋‹ค ์—ญ์‹œ ์‚ฌ๋žŒ์€ ๋ณต์Šต์ด ์ค‘์š”ํ•˜๊ณ  ๊พธ์ค€ํžˆ ๊ณต๋ถ€ํ•ด์•ผ ํ•œ๋‹ค,,, ์ด ๋ฌธ์ œ ์ฒ˜์Œ ํ’€์—ˆ์„ ๋• ๋‹ต์ด ๋„๋ฌด์ง€ ์•ˆ ๋‚˜์™”๋Š”๋ฐ ๋‹ค์‹œ ํ‘ธ๋‹ˆ๊นŒ ์‰ฝ๊ฒŒ ํ’€๋ฆผ from collections import deque n, m = map(int, input().split()) miro = [[] for _ in range(n)] for i in range(n): data =..

๋ฐฑ์ค€ 1012: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” (Python)

https://www.acmicpc.net/problem/1012 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net pypy3๋กœ ์ œ์ถœํ•จ. ๋“œ๋””์–ด dfs์™€ bfs๊ฐ€ ์ต์ˆ™ํ•ด์กŒ๋”ฐ......! # dfs def dfs(x, y): if x = m or y = n: return False if list[y][x] == 1: list[y][x] = 0 dfs(x+1, y) dfs(x-1, y) dfs(x, y+1) dfs(x, y-1) return True else: return False t = ..