๐Ÿ—๏ธ Algorithm 344

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 9663๋ฒˆ_N-Queen

๋ฌธ์ œ https://www.acmicpc.net/problem/9663 9663๋ฒˆ: N-Queen N-Queen ๋ฌธ์ œ๋Š” ํฌ๊ธฐ๊ฐ€ N × N์ธ ์ฒด์ŠคํŒ ์œ„์— ํ€ธ N๊ฐœ๋ฅผ ์„œ๋กœ ๊ณต๊ฒฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋†“๋Š” ๋ฌธ์ œ์ด๋‹ค. N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ํ€ธ์„ ๋†“๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 9663๋ฒˆ ๋ฌธ์ œ - N-Queen import sys input = sys.stdin.readline n = int(input().rstrip()) answer = 0 row = [0] * n def is_promising(x): for i in range(x): if row[x] == row[i] or abs(row[x]-row[i]) == abs(x-i): return False retur..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 5052๋ฒˆ_์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก

๋ฌธ์ œ https://www.acmicpc.net/problem/5052 5052๋ฒˆ: ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ t๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ t ≤ 50) ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์งธ ์ค„์—๋Š” ์ „ํ™”๋ฒˆํ˜ธ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n ≤ 10000) ๋‹ค์Œ n๊ฐœ์˜ ์ค„์—๋Š” ๋ชฉ๋ก์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 5052๋ฒˆ ๋ฌธ์ œ - ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) phone_book = [str(sys.stdin.readline().strip()) for _ in range(n)] # ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ›๋Š”๋‹ค. phone..

โฌ› [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] ์••์ถ•

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/17684/solution_groups?language=python3 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์••์ถ• def solution(msg): answer = [] d = {chr(65+i) : i+1 for i in range(26)} w, c = 0, 0 while True: c += 1 if c == len(msg): answer.append(d[msg[w:c]]) break if msg[w:c+1..

โฌ› [Programmers] [Python] [Level1] ์ถ”์–ต ์ ์ˆ˜

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/176963 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 1๋‹จ๊ณ„ - ์ถ”์–ต ์ ์ˆ˜ def solution(name, yearning, photo): answer = [] d = {} for i in range(len(name)): d[name[i]] = yearning[i] for i in range(len(photo)): res =0 for j in range(len(photo[i])): if photo[i][j] in d: ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver4] 1302๋ฒˆ_๋ฒ ์ŠคํŠธ์…€๋Ÿฌ

๋ฌธ์ œ https://www.acmicpc.net/problem/1302 1302๋ฒˆ: ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ ์ฒซ์งธ ์ค„์— ์˜ค๋Š˜ ํ•˜๋ฃจ ๋™์•ˆ ํŒ”๋ฆฐ ์ฑ…์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๊ฐ’์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์ฑ…์˜ ์ œ๋ชฉ์ด ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ๋‹ค. ์ฑ…์˜ ์ œ๋ชฉ์˜ ๊ธธ์ด๋Š” 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๊ณ  www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1302๋ฒˆ ๋ฌธ์ œ - ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ n = int(input()) book = {} for _ in range(n): name = input() if name not in book: book[name] = 0 book[name] += 1 print(sorted(list(book.items()), key=lambda x : (-x[1],x[0]))[0][0]) sort๋ฅผ ์ด์šฉํ•ด..

โฌ› [Programmers] [Python] [Level3] ์•ผ๊ทผ ์ง€์ˆ˜

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/12927 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์•ผ๊ทผ ์ง€์ˆ˜ import heapq def solution(n, works): answer = 0 heap = [] # ์‹œ๊ฐ„์•ˆ์— ์ž‘์—…์„ ๋๋‚ผ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ if sum(works) 0: work = heapq.heappop(heap)[1] - 1 heapq.heappush(heap, (-work, work)) n -= 1 for h in heap: if h[1]..

โฌ› [Programmers] [Python] [2022 KAKAO BLIND RECRUITMENT] [Level2] K์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ

๋ฌธ์ œ https://school.programmers.co.kr/learn/challenges?order=acceptance_desc&statuses=unsolved&levels=2%2C3%2C1&languages=python3 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์Šค์ฟจ ๊ฐœ๋ฐœ์ž ์ทจ์—…์˜ ํ•„์ˆ˜ ๊ด€๋ฌธ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋ฅผ ์ฒ ์ €ํ•˜๊ฒŒ ์—ฐ์Šตํ•˜๊ณ  ๋Œ€๋น„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ฅผ ์ด๋ง๋ผ! ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์—์„œ ์„ ๋ฐœํ•œ ๋ฌธ์ œ๋กœ ์œ ํ˜•์„ ํŒŒ์•…ํ•˜๊ณ  ์‹ค๋ ฅ์„ ์—…๊ทธ๋ ˆ์ด๋“œํ•ด ๋ณด์„ธ์š”! school.programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ import math def isPrime(n): if n == 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n ..

โฌ› [Programmers] [Python] [Level2] ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/42577 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก def solution(phone_book): hash_map = {} for phone_number in phone_book: hash_map[phone_number] = 1 for phone_number in phone_book: s = "" for number in phone_number: s += number if s in hash_map..

โฌ› [Programmers] [Python] [Level3] ์ด์ค‘ ์šฐ์„ ์ˆœ์œ„ ํ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/42628 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 3๋‹จ๊ณ„ - ์ด์ค‘ ์šฐ์„ ์ˆœ์œ„ ํ import heapq def solution(operations): heap = [] max_heap = [] for o in operations: current = o.split() if current[0] == 'I': num = int(current[1]) heapq.heappush(heap, num) # ์ตœ์†Œ ํž™ heapq.heapp..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 4179๋ฒˆ_๋ถˆ!

๋ฌธ์ œ https://www.acmicpc.net/problem/4179 4179๋ฒˆ: ๋ถˆ! ์ž…๋ ฅ์˜ ์ฒซ์งธ ์ค„์—๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋œ ๋‘ ์ •์ˆ˜ R๊ณผ C๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹จ, 1 ≤ R, C ≤ 1000 ์ด๋‹ค. R์€ ๋ฏธ๋กœ ํ–‰์˜ ๊ฐœ์ˆ˜, C๋Š” ์—ด์˜ ๊ฐœ์ˆ˜์ด๋‹ค. ๋‹ค์Œ ์ž…๋ ฅ์œผ๋กœ R์ค„๋™์•ˆ ๊ฐ๊ฐ์˜ ๋ฏธ๋กœ ํ–‰์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ๊ฐ์˜ ๋ฌธ์ž www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 4179๋ฒˆ ๋ฌธ์ œ - ๋ถˆ! import sys from collections import deque input = sys.stdin.readline n, m = map(int, input().split()) graph = [] for i in range(n): graph.append(list(input().rstrip())) if 'J' in graph[i]: q..