Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป
๋ฐ˜์‘ํ˜•

Algorithm 237

[๋ฐฑ์ค€] (Swift) 11724๋ฒˆ - ์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜ (DFS ์—ฐ์Šต)

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/11724 11724๋ฒˆ: ์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜ ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N๊ณผ ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 1,000, 0 ≤ M ≤ N×(N-1)/2) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์— ๊ฐ„์„ ์˜ ์–‘ ๋์  u์™€ v๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ u, v ≤ N, u ≠ v) ๊ฐ™์€ ๊ฐ„์„ ์€ ํ•œ ๋ฒˆ๋งŒ ์ฃผ www.acmicpc.net ๋ฌธ์ œ ํ’€์ด ๋‚˜๋Š” ์•„์ง graph๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๊ฒŒ ํž˜๋“ค๋‹ค. ์ด๋ฒˆ์— ์‚ฌ์šฉํ•œ ๋ฐฉ์‹์€, ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. graph๋ผ๋Š” 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ , ๊ทธ ์•ˆ์— ์—ฐ๊ฒฐ๋œ ๋…ธ๋“œ๋“ค๋กœ ์ฑ„์›Œ์ฃผ์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋ฅผ ์„ ํƒํ•˜๊ณ , ๊ทธ ๊นŠ์ด๋ฅผ ์ „์ฒด ๋‹ค ํƒ์ƒ‰ํ•œ ํ•œ๋‹ค์Œ, ์—ฐ๊ฒฐ์ด ๋Š๊ธฐ๋ฉด!! ์ƒˆ๋กœ์šด ๊ทธ๋ž˜ํ”„๋ฅผ ํƒ์ƒ‰ํ•ด์•ผํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— DFS ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ–ˆ๋‹ค. ๋งˆ์ง€..

Algorithm/Baekjoon 2022.05.20

[๋ฐฑ์ค€] (Swift) 14501๋ฒˆ - ํ‡ด์‚ฌ (DP๋กœ ํ’€๊ธฐ)

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/14501 14501๋ฒˆ: ํ‡ด์‚ฌ ์ฒซ์งธ ์ค„์— ๋ฐฑ์ค€์ด๊ฐ€ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ์ด์ต์„ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ์ฝ”๋“œ var n = Int(readLine()!)! var tp: [[Int]] = [] var dp = Array(repeating: 0, count: 100) for i in 0..

Algorithm/Baekjoon 2022.05.17

[๋ฐฑ์ค€] (Swift) 1260๋ฒˆ - DFS์™€ BFS

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/1260 1260๋ฒˆ: DFS์™€ BFS ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 1,000), ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ M(1 ≤ M ≤ 10,000), ํƒ์ƒ‰์„ ์‹œ์ž‘ํ•  ์ •์ ์˜ ๋ฒˆํ˜ธ V๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ„์„ ์ด ์—ฐ๊ฒฐํ•˜๋Š” ๋‘ ์ •์ ์˜ ๋ฒˆํ˜ธ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์–ด๋–ค ๋‘ ์ •์  ์‚ฌ www.acmicpc.net ๋ฌธ์ œ ํ’€์ด https://didu-story.tistory.com/98 [์•Œ๊ณ ๋ฆฌ์ฆ˜] ํƒ์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜ DFS, BFS -- ๋ณธ ํฌ์ŠคํŒ…์€ ์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ ์ฑ…์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 1. DFS Depth First Search, ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰ ๊ทธ๋ž˜ํ”„์˜ ๊นŠ์€ ๋ถ€๋ถ„์„ ์šฐ์„ ์ ์œผ๋กœ ํƒ์ƒ‰ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฃผ๋กœ ์Šค didu-sto..

Algorithm/Baekjoon 2022.05.14

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Swift) Kakao - ๋ฉ”๋‰ด ๋ฆฌ๋‰ด์–ผ

๋ฌธ์ œ ๋งํฌ https://programmers.co.kr/learn/courses/30/lessons/72411 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฉ”๋‰ด ๋ฆฌ๋‰ด์–ผ ๋ ˆ์Šคํ† ๋ž‘์„ ์šด์˜ํ•˜๋˜ ์Šค์นดํ”ผ๋Š” ์ฝ”๋กœ๋‚˜19๋กœ ์ธํ•œ ๋ถˆ๊ฒฝ๊ธฐ๋ฅผ ๊ทน๋ณตํ•˜๊ณ ์ž ๋ฉ”๋‰ด๋ฅผ ์ƒˆ๋กœ ๊ตฌ์„ฑํ•˜๋ ค๊ณ  ๊ณ ๋ฏผํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด์—๋Š” ๋‹จํ’ˆ์œผ๋กœ๋งŒ ์ œ๊ณตํ•˜๋˜ ๋ฉ”๋‰ด๋ฅผ ์กฐํ•ฉํ•ด์„œ ์ฝ”์Šค์š”๋ฆฌ ํ˜•ํƒœ๋กœ ์žฌ๊ตฌ์„ฑํ•ด์„œ programmers.co.kr ๋ฌธ์ œ ์„ค๋ช… ์ž…์ถœ๋ ฅ[์˜ˆ]๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค orders orders์— ์‚ฌ๋žŒ๋“ค์ด ์ฃผ๋ฌธํ•œ ์ฃผ๋ฌธ๋‚ด์—ญ์ด ๋“ค์–ด์žˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ 1๋ฒˆ์œผ๋กœ ๋ณด๋ฉด 6๋ช…์˜ ์‚ฌ๋žŒ๋“ค์ด ์ฃผ๋ฌธํ–ˆ๋‹ค. ์ฒซ๋ฒˆ์งธ ์‚ฌ๋žŒ์€ "ABCFG" ๋ฉ”๋‰ด๋ฅผ ์ฃผ๋ฌธํ–ˆ๋‹ค. A๋ฉ”๋‰ด, B๋ฉ”๋‰ด,,,, course ์ฃผ์ธ๊ณต '์Šค์นดํ”ผ'๋Š” ์ฝ”์Šค๋ฉ”๋‰ด๋ฅผ ๊ตฌ์„ฑ์ค‘์ด๋‹ค. [2, 3, 4] ๋ผ๋Š” ์˜๋ฏธ๋Š”, 2๊ฐ€์ง€ ๋ฉ”๋‰ด๋กœ ๊ตฌ์„ฑ๋œ ์ฝ”์Šค, 3๊ฐ€์ง€ ๋ฉ”๋‰ด๋กœ..

[๋ฐฑ์ค€] (Swift) 1759๋ฒˆ - ์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/1759 1759๋ฒˆ: ์•”ํ˜ธ ๋งŒ๋“ค๊ธฐ ์ฒซ์งธ ์ค„์— ๋‘ ์ •์ˆ˜ L, C๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (3 ≤ L ≤ C ≤ 15) ๋‹ค์Œ ์ค„์—๋Š” C๊ฐœ์˜ ๋ฌธ์ž๋“ค์ด ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ๋ฌธ์ž๋“ค์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์ด๋ฉฐ, ์ค‘๋ณต๋˜๋Š” ๊ฒƒ์€ ์—†๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ๋ชจ์Œ๊ณผ ์ž์Œ์„ ๋ชจ๋‘ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ค์–ด์ค€ ๋’ค, ์—ฌ๊ธฐ์— ๋ชจ์Œ์ด ํ•œ๊ฐœ ์ด์ƒ ํฌํ•จ๋˜๋Š”์ง€์™€ ์ž์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋”ฐ์ ธ์ฃผ์—ˆ๋‹ค. dfs๋ฅผ ์ด์šฉํ•ด์„œ ํ’€์—ˆ๋‹ค. ์ค‘๋ณต์ด ํ—ˆ์šฉ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ๋ฐฉ๋ฌธ์ฒดํฌ๋ฅผ ํ•ด๊ฐ€๋ฉด์„œ ํ’€์—ˆ๋‹ค. let LC = readLine()!.split(separator: " ").map{ Int(String($0))! } let l = LC[0] let c = LC[1] var charLis..

Algorithm/Baekjoon 2022.05.10

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Swift) Kakao ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ

๋ฌธ์ œ๋งํฌ https://programmers.co.kr/learn/courses/30/lessons/92341 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ [180, 5000, 10, 600] ["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"] [14600, 34400, 5000] programmers.co.kr ๋ฌธ์ œ ํ•ด์„ ๋ฐ ํ’€์ด fees ์—์„œ ์ฒซ๋ฒˆ์งธ๋Š” ๊ธฐ๋ณธ ์ฃผ์ฐจ ์‹œ๊ฐ„, ๋‘๋ฒˆ์งธ๋Š” ๊ธฐ๋ณธ ์ฃผ์ฐจ ์š”๊ธˆ, ์„ธ๋ฒˆ์งธ๋Š” ์ฃผ์ฐจ์š”๊ธˆ์„ ๊ณ„์‚ฐํ•˜๋Š” ๋‹จ์œ„ (๋ถ„), ๋„ค๋ฒˆ์งธ๋Š” ๋‹จ์œ„๋‹น ์–ผ๋งˆ?๋ฅผ ์˜๋ฏธํ•œ๋‹ค. recor..

[๋ฐฑ์ค€] (Swift) 15654๋ฒˆ - N๊ณผ M (5) (DFS๋กœ ํ’€๊ธฐ!)

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/15654 15654๋ฒˆ: N๊ณผ M (5) N๊ฐœ์˜ ์ž์—ฐ์ˆ˜์™€ ์ž์—ฐ์ˆ˜ M์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์•„๋ž˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๊ธธ์ด๊ฐ€ M์ธ ์ˆ˜์—ด์„ ๋ชจ๋‘ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. N๊ฐœ์˜ ์ž์—ฐ์ˆ˜๋Š” ๋ชจ๋‘ ๋‹ค๋ฅธ ์ˆ˜์ด๋‹ค. N๊ฐœ์˜ ์ž์—ฐ์ˆ˜ ์ค‘์—์„œ M๊ฐœ๋ฅผ ๊ณ ๋ฅธ ์ˆ˜์—ด www.acmicpc.net ๋ฌธ์ œํ’€์ด ์ง€๋‚œ๋ฒˆ์— ํŒ€์› ํ•œ๋ถ„์ด ๋ง์”€ํ•ด์ฃผ์…จ๋˜ ๊ฟ€ํŒ์ด ์ƒ๊ฐ๋‚ฌ๋‹ค. ์ถœ๋ ฅ๋˜๋Š” ์ˆœ์—ด์—์„œ, [ 1 1 ] [ 2 2 ] ์™€ ๊ฐ™์ด ์ค‘๋ณต๋˜๋Š” ๊ฐ’์ด ์•ˆ๋“ค์–ด์žˆ์ง€ ์•Š์€๊ฐ€? ๊ทธ๋ ‡๋‹ค๋ฉด visited ์ฒดํฌ๋ฅผ ํ•œ๋‹ค๋Š” ๋œป์ด๋‹ค! ์ด ๋ง์„ ๊ธฐ์–ตํ•˜๋ฉด์„œ ์ฐจ๊ทผ์ฐจ๊ทผ dfs๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค. dfs๋กœ ๊ตฌํ˜„ํ•œ ์ด์œ ๋Š”? ์ˆœ์—ด์— ๋‹ด๊ธฐ ์œ„ํ•ด์„œ ๋ชจ๋“  ์ˆ˜๋ฅผ ํƒ์ƒ‰ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค! ๋ฆฌ์ŠคํŠธ๋กœ ๋‹ด์€ ๊ฒƒ์„ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์ด ์ •๋ง ์–ด๋ ค์› ๋‹ค. ํŒ€์›๋“ค..

Algorithm/Baekjoon 2022.05.04

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Swift) Kakao ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ

๋ฌธ์ œ ๋งํฌ https://programmers.co.kr/learn/courses/30/lessons/92334 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜ programmers.co.kr ๋ฌธ์ œ ํ’€์ด ์šฐ์„  ์‹ ๊ณ  ๋‹นํ•œ์‚ฌ๋žŒ์„ ๊ธฐ์ค€์œผ๋กœ ์‹ ๊ณ  ํ•œ์‚ฌ๋žŒ์—๊ฒŒ ๋ฉ”์ผ์„ ๋ณด๋‚ด๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— dictionary๋ฅผ ์„ค์ •ํ•  ๋•Œ "์‹ ๊ณ ๋‹นํ•œ์‚ฌ๋žŒ์„ Key"๋กœ ๋‘๊ณ , "์‹ ๊ณ  ํ•œ ์‚ฌ๋žŒ์„ Value"๋กœ ๋‘์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋‚ด๊ฐ€ ์„ ์–ธํ•˜ ๋ณ€์ˆ˜๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. reported_report ๋”•์…”๋„ˆ๋ฆฌ : ์‹ ๊ณ ๋‹นํ•œ์‚ฌ๋žŒkey, ์‹ ๊ณ ํ•œ์‚ฌ๋žŒvalue ์–ผ๋งˆ๋‚˜ ์‹ ๊ณ ๋ฅผ ๋‹นํ–ˆ๋Š”์ง€ ์„ธ์–ด์ค„..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Swift) Kakao ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„

๋ฌธ์ œ ๋งํฌ https://programmers.co.kr/learn/courses/30/lessons/64061 ๋ฌธ์ œ ํ’€์ด board ์—์„œ ๋ฝ‘๋Š” ์ธํ˜• pickDoll pickDoll์„ ๋„ฃ๋Š” ๋ฐ”๊ตฌ๋‹ˆ๋Š” baguni ์ด๋™ํ•˜๋ ค๋Š” ๊ฒฝ๋กœ moves ๋„ค์ผ ์œ„์—์žˆ๋Š” ๊ฒƒ๋“ค์„ ํƒ์ƒ‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” baguni[i][move-1]์„ ํ•ด์•ผ ์›ํ•˜๋Š” ์œ„์น˜์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ณ , ์ด๋•Œ ์ด ๊ฐ’์ด 0์ด๋ผ๋ฉด i๋ฅผ ๋ฐ”๊ฟ”์ฃผ๋ฉฐ ๋ฐ‘์—์žˆ๋Š” ๊ฐ’์„ ํƒ์ƒ‰ํ•ด์•ผํ•œ๋‹ค. baguni์— ๋‘ ๊ฐœ์ด์ƒ ๊ฒน์น˜๋Š” ์ธํ˜•์ด ๋‚˜์˜ค๋ฉด, result ์—๋‹ค๊ฐ€ ๊ทธ ๊ฐœ์ˆ˜๋ฅผ + ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๋ฌธ์ œ ํ’€๋‹ค๊ฐ€ ๋ฐœ๊ฒฌํ•œ ์ด์Šˆ์‚ฌํ•ญ if baguni.count != 0 && pickDoll == baguni[baguni.count-1] { } // ์ •๋‹ต if pickDoll == baguni[bagu..

[๋ฐฑ์ค€] (Swift) 15651๋ฒˆ - N๊ณผ M (3)

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/15651 15651๋ฒˆ: N๊ณผ M (3) ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๋ฌธ์ œ์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ˆ˜์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ˆ˜์—ด์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ถœ๋ ฅํ•˜๋ฉด ์•ˆ๋˜๋ฉฐ, ๊ฐ ์ˆ˜์—ด์€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ์ˆ˜์—ด์€ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ถœ๋ ฅํ•ด www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด permutation ์œผ๋กœ ์ง„ํ–‰ํ•˜๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฐ™์€ ์ˆ˜ ๋ฐ˜๋ณต์ด ์•ˆ๋๋‹ค. ๊ฐ™์€์ˆ˜๋ฅผ ๋ฐ˜๋ณตํ•ด์„œ ์ถœ๋ ฅํ•ด์ฃผ๊ณ , permutation ๊ฒฐ๊ณผ๋“ค์„ ์ถœ๋ ฅํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ์ƒ๊ฐ์ฒ˜๋Ÿผ ์ž˜ ๋˜์ง€ ์•Š์•˜๋‹ค. func solution() { let arr = readLine()!.split(separator: " ").map{Int(String($0))!} let n = arr[0] ..

Algorithm/Baekjoon 2022.04.25
๋ฐ˜์‘ํ˜•