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

๋ฐฑ์ค€ 2667: ๋‹จ์ง€๋ฒˆํ˜ธ๋ถ™์ด๊ธฐ (Python)

https://www.acmicpc.net/problem/2667 2667๋ฒˆ: ๋‹จ์ง€๋ฒˆํ˜ธ๋ถ™์ด๊ธฐ ๊ณผ ๊ฐ™์ด ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ์ง€๋„๊ฐ€ ์žˆ๋‹ค. 1์€ ์ง‘์ด ์žˆ๋Š” ๊ณณ์„, 0์€ ์ง‘์ด ์—†๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ฒ ์ˆ˜๋Š” ์ด ์ง€๋„๋ฅผ ๊ฐ€์ง€๊ณ  ์—ฐ๊ฒฐ๋œ ์ง‘์˜ ๋ชจ์ž„์ธ ๋‹จ์ง€๋ฅผ ์ •์˜ํ•˜๊ณ , ๋‹จ์ง€์— ๋ฒˆํ˜ธ๋ฅผ ๋ถ™์ด๋ ค ํ•œ๋‹ค. ์—ฌ www.acmicpc.net ๋ฆฌ์ŠคํŠธ ๋Œ๋ฉด์„œ ํ•ด๋‹น ๋ฐ์ดํ„ฐ๊ฐ€ 1์ด๋ฉด ์ƒํ•˜์ขŒ์šฐ ์‚ดํ”ผ๋ฉด์„œ ๊ทธ๋ž˜ํ”„๋ฅผ ํƒ์ƒ‰ํ•œ๋‹ค. ์ฝ”๋“œ๊ฐ€ ๋งค์šฐ ๋„ˆ์ €๋ถ„ํ•œ ๋Š๋‚Œ,,, # dfs n = int(input()) list = [[] for _ in range(n)] for i in range(n): data = input() for j in range(n): list[i].append(int(data[j])) def dfs(x, y): if x ..

๋ฐฑ์ค€ 2606: ๋ฐ”์ด๋Ÿฌ์Šค (Python)

https://www.acmicpc.net/problem/2606 2606๋ฒˆ: ๋ฐ”์ด๋Ÿฌ์Šค ์ฒซ์งธ ์ค„์—๋Š” ์ปดํ“จํ„ฐ์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ปดํ“จํ„ฐ์˜ ์ˆ˜๋Š” 100 ์ดํ•˜์ด๊ณ  ๊ฐ ์ปดํ“จํ„ฐ์—๋Š” 1๋ฒˆ ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ๋ฒˆํ˜ธ๊ฐ€ ๋งค๊ฒจ์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๋„คํŠธ์›Œํฌ ์ƒ์—์„œ ์ง์ ‘ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” ์ปดํ“จํ„ฐ ์Œ์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด www.acmicpc.net bfs ๋จผ์ € ํ’€๊ณ  dfs ํ’€์—ˆ๋‹ค # bfs from collections import deque n = int(input()) m = int(input()) com = [[] for _ in range(n+1)] for i in range(m): data = input().split() com[int(data[0])].append(int(data[1])) com[int(data[1])].append(i..

๋ฐฑ์ค€ 1260: DFS์™€ BFS (Python)

https://www.acmicpc.net/problem/1260 1260๋ฒˆ: DFS์™€ BFS ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 1,000), ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M(1 ≤ M ≤ 10,000), ํƒ์ƒ‰์„ ์‹œ์ž‘ํ•  ์ •์ ์˜ ๋ฒˆํ˜ธ V๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ„์„ ์ด ์—ฐ๊ฒฐํ•˜๋Š” ๋‘ ์ •์ ์˜ ๋ฒˆํ˜ธ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์–ด๋–ค ๋‘ ์ •์  ์‚ฌ www.acmicpc.net from collections import deque n, m, v = map(int, input().split()) graph = [[] for _ in range(n+1)] for i in range(m): data = input().split() graph[int(data[0])].append(int(data[1])) graph[int(data[1])]...

๋ฐฑ์ค€ 13305: ์ฃผ์œ ์†Œ (Python)

https://www.acmicpc.net/problem/13305 13305๋ฒˆ: ์ฃผ์œ ์†Œ ํ‘œ์ค€ ์ž…๋ ฅ์œผ๋กœ ๋‹ค์Œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ๋„์‹œ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜ N(2 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ ์ค„์—๋Š” ์ธ์ ‘ํ•œ ๋‘ ๋„์‹œ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๋„๋กœ์˜ ๊ธธ์ด๊ฐ€ ์ œ์ผ ์™ผ์ชฝ ๋„๋กœ๋ถ€ํ„ฐ N-1 www.acmicpc.net ๋ฐฑ์ค€ ์˜ค๋žœ๋งŒ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ธฐ๋ง๊ณ ์‚ฌ ๋•Œ ๋‚˜์™”๋˜ ๋ฌธ์ œ๋ผ์„œ ๋ฐ˜๊ฐ€์› ๋‹ค. ํ•˜์ง€๋งŒ ๊ธฐ์–ต ์•ˆ ๋‚จ. ์‹œํ—˜ ๋•Œ๋„ ์‹œ๊ฐ„์ด ์—†๊ธฐ๋„ ํ•ด์„œ ๊ฑ ๋Œ€์ถฉ ํœ˜๊ฐˆ๊ฒจ ์ผ๋˜ ๊ธฐ์–ต. ์ข€๋” ๋ฏธ๋ฆฌ ํ’€์–ด๋ณผ๊ฑธ ์กฐ๊ธˆ ์–ต์šธํ–ˆ์Œ,,, ์ฒ˜์Œ์— ๊ฝค ๋ณต์žกํ•˜๊ฒŒ ์ƒ๊ฐํ–ˆ๋‹ค. ๊ทผ๋ฐ ํ’€๋ฉด์„œ๋Š” ๋ฌธ์ œ๊ฐ€ ๊ฐ„๋‹จํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Œ. n = int(input()) length = list(map(int, input().split())) price = list(ma..

๋ฐฑ์ค€ 1789: ์ˆ˜๋“ค์˜ ํ•ฉ (Python)

https://www.acmicpc.net/problem/1789 1789๋ฒˆ: ์ˆ˜๋“ค์˜ ํ•ฉ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ S(1 ≤ S ≤ 4,294,967,295)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net import sys s = int(sys.stdin.readline()) res = 0 for i in range(s+1): if s == 1: res = 1 break if i * (i + 1) // 2 > s: res = i - 1 break print(res) ๋ญ”๊ฐ€.. ์ค‘๊ตฌ๋‚œ๋ฐฉํ•จ import sys s = int(sys.stdin.readline()) n = 1 while n * (n + 1) // 2

๋ฐฑ์ค€ 1946: ์‹ ์ž… ์‚ฌ์› (Python)

https://www.acmicpc.net/problem/1946 1946๋ฒˆ: ์‹ ์ž… ์‚ฌ์› ์ฒซ์งธ ์ค„์—๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T(1 ≤ T ≤ 20)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์งธ ์ค„์— ์ง€์›์ž์˜ ์ˆซ์ž N(1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ ์ค„์—๋Š” ๊ฐ๊ฐ์˜ ์ง€์›์ž์˜ ์„œ๋ฅ˜์‹ฌ์‚ฌ ์„ฑ www.acmicpc.net ์ฒ˜์Œ ํ‘ผ ์ฝ”๋“œ - ์‹œ๊ฐ„ ์ดˆ๊ณผ import sys t = int(sys.stdin.readline()) for i in range(t): n = int(sys.stdin.readline()) list1 = [0 for i in range(n)] list2 = [0 for i in range(n)] for j in range(n): r1, r2 = map(int, sys.stdi..

๋ฐฑ์ค€ 10162: ์ „์ž๋ ˆ์ธ์ง€ (Python)

import sys t = int(sys.stdin.readline()) time = [300, 60, 10] cnt = [] for i in time: cnt.append(t // i) t %= i if t == 0: print(cnt[0], cnt[1], cnt[2]) else: print(-1) ๊ฑฐ์Šค๋ฆ„๋ˆ ๋ฌธ์ œ๋ž‘ ๊ฑฐ์˜ ๋˜‘๊ฐ™๋‹ค ๋‹ค๋ฅธ๊ฒŒ ์žˆ๋‹ค๋ฉด ์‹œ๊ฐ„์ด ๋”ฑ ์•ˆ ๋งž์œผ๋ฉด -1 ์ถœ๋ ฅํ•œ๋‹ค๋Š” ๊ฒƒ๊ณผ ์ด ํšŸ์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฐ๊ฐ์˜ ํšŸ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ! ๊ทธ๋ž˜์„œ cnt๋„ ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ๊ฐ๊ฐ for๋ฌธ ๋Œ ๋•Œ๋งˆ๋‹ค ํšŸ์ˆ˜๋ฅผ cnt์— ์ถ”๊ฐ€ํ–ˆ๋‹ค ์ด๊ฑด ๊ทธ๋ƒฅ ์‹ ๊ธฐํ•ด์„œ...ใ…Ž ์„œ๋ธŒํƒœ์Šคํฌ ๋ฌธ์ œ ์ฒ˜์Œ ํ’€์–ด๋ดค๋Š”๋ฐ ๋งž์•˜์Šต๋‹ˆ๋‹ค!!๊ฐ€ ์•„๋‹Œ ์ ์ˆ˜๊ฐ€ ๋‚˜์˜จ๋‹ค

๋ฐฑ์ค€ 2217: ๋กœํ”„ (Python)

https://www.acmicpc.net/problem/2217 2217๋ฒˆ: ๋กœํ”„ N(1 ≤ N ≤ 100,000)๊ฐœ์˜ ๋กœํ”„๊ฐ€ ์žˆ๋‹ค. ์ด ๋กœํ”„๋ฅผ ์ด์šฉํ•˜์—ฌ ์ด๋Ÿฐ ์ €๋Ÿฐ ๋ฌผ์ฒด๋ฅผ ๋“ค์–ด์˜ฌ๋ฆด ์ˆ˜ ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ๋กœํ”„๋Š” ๊ทธ ๊ตต๊ธฐ๋‚˜ ๊ธธ์ด๊ฐ€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ฌผ์ฒด์˜ ์ค‘๋Ÿ‰์ด ์„œ๋กœ ๋‹ค๋ฅผ ์ˆ˜๋„ ์žˆ๋‹ค. ํ•˜ www.acmicpc.net ์ฒ˜์Œ์—” ๋ฌด์กฐ๊ฑด n๊ฐœ์˜ ๋กœํ”„๋ฅผ ์จ์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋กœํ”„์˜ ์ตœ์†Ÿ๊ฐ’ * ๋กœํ”„์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ–ˆ๋‹ค - ํ‹€๋ฆผ n = int(input()) m = 10000 for i in range(n): rope = int(input()) if rope < m: m = rope print(m * n) ๋‹ค์‹œ ํ‘ผ ์ฝ”๋“œ import sys n = int(sys.stdin.readline()) rope = [] re..

๋ฐฑ์ค€ 5585: ๊ฑฐ์Šค๋ฆ„๋ˆ (Python)

https://www.acmicpc.net/problem/5585 5585๋ฒˆ: ๊ฑฐ์Šค๋ฆ„๋ˆ ํƒ€๋กœ๋Š” ์ž์ฃผ JOI์žกํ™”์ ์—์„œ ๋ฌผ๊ฑด์„ ์‚ฐ๋‹ค. JOI์žกํ™”์ ์—๋Š” ์ž”๋ˆ์œผ๋กœ 500์—”, 100์—”, 50์—”, 10์—”, 5์—”, 1์—”์ด ์ถฉ๋ถ„ํžˆ ์žˆ๊ณ , ์–ธ์ œ๋‚˜ ๊ฑฐ์Šค๋ฆ„๋ˆ ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ์ ๊ฒŒ ์ž”๋ˆ์„ ์ค€๋‹ค. ํƒ€๋กœ๊ฐ€ JOI์žกํ™”์ ์—์„œ ๋ฌผ๊ฑด์„ ์‚ฌ www.acmicpc.net n = int(input()) cash = [500, 100, 50, 10, 5, 1] k = 1000 - n cnt = 0 for i in cash: cnt += k // i k %= i print(cnt) ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ฑฐ์Šค๋ฆ„๋ˆ ๋ฌธ์ œ๋ฅผ ์˜ˆ์‹œ๋กœ ๋“ค์–ด์„œ ๊ณต๋ถ€ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์—ˆ๋‹ค!

๋ฐฑ์ค€ 1026: ๋ณด๋ฌผ (Python)

https://www.acmicpc.net/problem/1026 1026๋ฒˆ: ๋ณด๋ฌผ ์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” A์— ์žˆ๋Š” N๊ฐœ์˜ ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง€๊ณ , ์…‹์งธ ์ค„์—๋Š” B์— ์žˆ๋Š” ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , A์™€ B์˜ ๊ฐ ์›์†Œ๋Š” 100๋ณด๋‹ค ์ž‘๊ฑฐ www.acmicpc.net n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort(reverse=True) res = 0 for i in range(n): res += a[i] * b[i] print(res)