๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ“– Problem Solution204

[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ณผ ๋Š‘๋Œ€ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ณผ ๋Š‘๋Œ€ [0,0,1,1,1,0,1,0,1,0,1,1] [[0,1],[1,2],[1,4],[0,8],[8,7],[9,10],[9,11],[4,3],[6,5],[4,6],[8,9]] 5 [0,1,0,1,1,0,1,0,0,1,0] [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[4,8],[6,9],[9,10]] 5 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์™„์ „ํƒ์ƒ‰๊ณผ DFS๋กœ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. edge๋ฅผ ์ด์šฉํ•ด ๋ถ€๋ชจ์™€ ์ž์‹์„ ์—ฐ๊ฒฐํ•ด์ค๋‹ˆ๋‹ค. func connectEdge(_ edges:[[Int]]) { for edge in edges { if pc[edge[0]] == nil { pc[edge[0]] = [edg.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ถ๋Œ€ํšŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ถ๋Œ€ํšŒ ๋ฌธ์ œ ์„ค๋ช… ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ๊ฐ€ ์—ด๋ ธ์Šต๋‹ˆ๋‹ค. ๋ผ์ด์–ธ์€ ์ €๋ฒˆ ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šฐ์Šน์ž์ด๊ณ  ์ด๋ฒˆ ๋Œ€ํšŒ์—๋„ ๊ฒฐ์Šน์ „๊นŒ์ง€ ์˜ฌ๋ผ์™”์Šต๋‹ˆ๋‹ค. ๊ฒฐ์Šน์ „ ์ƒ๋Œ€๋Š” ์–ดํ”ผ์น˜์ž…๋‹ˆ๋‹ค. ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šด์˜์œ„์› programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” DFS ๋ฐ ์™„์ „ํƒ์ƒ‰ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ๊ฐ ์ ์ˆ˜๋งˆ๋‹ค ์ด๊ธธ์ง€ ์งˆ์ง€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. 10์ ๋ถ€ํ„ฐ 1์ ๊นŒ์ง€ ์–ดํ”ผ์น˜๋ฅผ ์ด๊ธธ ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ํŒ๋ณ„ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด๊ธธ ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ์ ์ˆ˜๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•๊ณผ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์ด์„œ ๋‹ค๋ฅธ ์ ์ˆ˜๋ฅผ ์–ป์„ ๋ฐฉ๋ฒ•์„ ํƒํ•ฉ๋‹ˆ๋‹ค. DFS๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ์™€ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์˜๊ณ  ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐˆ ๊ฒฝ์šฐ 2๊ฐ€์ง€๋ฅผ ์žฌ๊ท€ํ•ด์ค๋‹ˆ๋‹ค. func dfs(leftArrow:Int,depth:Int,history:[Int],info:[.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ [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 Solution 1. records์˜ ๊ธฐ๋ก๋Œ€๋กœ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•ด ์ €์žฅํ•œ๋‹ค. var timeInfo:[String:Int] = [:] var parkInfo:[String:Int] = [:] func calTimeByRecord(_ records:[String],_ parkIn.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์–‘์˜ ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ k์ง„์ˆ˜๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ, ๋ณ€ํ™˜๋œ ์ˆ˜ ์•ˆ์— ์•„๋ž˜ ์กฐ๊ฑด์— ๋งž๋Š” ์†Œ์ˆ˜(Prime number)๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€ ์•Œ์•„๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. 0P0์ฒ˜๋Ÿผ ์†Œ์ˆ˜ ์–‘์ชฝ์— 0์ด ์žˆ๋Š” ๊ฒฝ์šฐ P0์ฒ˜๋Ÿผ ์†Œ programmers.co.kr Solution 1. n์„ k์ง„์ˆ˜๋กœ ๋ฐ”๊พผ๋‹ค. let change = String(n,radix: k) 2. ๋ฐ”๊พผ ๋ฌธ์ž๋ฅผ 0์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค. let numbers = change.split(separator: "0") 3. ์†Œ์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•œ๋‹ค. func isPrimeNumber(_ n:Int) -> Bool { if n == 1 { return false } if n == 2 || n == 3 {.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜ programmers.co.kr Solution 1. id_list๋ฅผ ์ธ๋ฑ์Šค์— ๋งž๊ฒŒ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค. var idNumber:[String:Int] = [:] for (i,id) in id_list.enumerated() { idNumber[id] = i } 2. ์‹ ๊ณ  ๋‹นํ•œ ์‚ฌ๋žŒ์„ ํ‚ค๊ฐ’์œผ๋กœ,์‹ ๊ณ ํ•œ ์‚ฌ๋žŒ๋“ค์„ ๋ฐธ๋ฅ˜๊ฐ’์œผ๋กœ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค. var reportInfo:[String:Set] = [:] for r in report { let split = r.split(sepa.. 2022. 1. 19.
[Swift] Baekjoon 12919๋ฒˆ A์™€ B 2 Problem 12919๋ฒˆ: A์™€ B 2 ์ˆ˜๋นˆ์ด๋Š” A์™€ B๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ์˜์–ด ๋‹จ์–ด ์กด์žฌํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์— ๋†€๋ž๋‹ค. ๋Œ€ํ‘œ์ ์ธ ์˜ˆ๋กœ AB (Abdominal์˜ ์•ฝ์ž), BAA (์–‘์˜ ์šธ์Œ ์†Œ๋ฆฌ), AA (์šฉ์•”์˜ ์ข…๋ฅ˜), ABBA (์Šค์›จ๋ด ํŒ ๊ทธ๋ฃน)์ด ์žˆ๋‹ค. ์ด๋Ÿฐ ์‚ฌ์‹ค์— ๋†€๋ž€ ์ˆ˜๋นˆ www.acmicpc.net Solution A์™€ B๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” ์ด 4๊ฐ€์ง€ ์ž…๋‹ˆ๋‹ค. 1. A๋กœ ์‹œ์ž‘ํ•ด์„œ A๋กœ ๋๋‚˜๋Š” ๊ฒฝ์šฐ ์ด ๊ฒฝ์šฐ S์— A๋ฅผ ์ถ”๊ฐ€ํ–ˆ์„ ๊ฒฝ์šฐ์—๋งŒ ๋งŒ๋“ค์–ด์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ A๋ฅผ ์‚ญ์ œํ•ด์ค๋‹ˆ๋‹ค. 2. A๋กœ ์‹œ์ž‘ํ•ด์„œ B๋กœ ๋๋‚˜๋Š” ๊ฒฝ์šฐ ์ด ๊ฒฝ์šฐ๋Š” S์— ์–ด๋– ํ•œ ๊ฒฝ์šฐ๋„ ๋งŒ๋“ค ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. 3. B๋กœ ์‹œ์ž‘ํ•ด์„œ A๋กœ ๋๋‚˜๋Š” ๊ฒฝ์šฐ ์ด ๊ฒฝ์šฐ B๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๋’ค์ง‘์€ ๊ฒฝ์šฐ์ด๊ฑฐ๋‚˜ ๋‹จ์ง€ A๋ฅผ ์ถ”๊ฐ€ ํ–ˆ์„ ๊ฒฝ์šฐ๊ฐ€ ๋ชจ๋‘ ๊ฐ€๋Šฅ ํ•˜๋ฏ€.. 2022. 1. 7.
[Swift] Baekjoon ํŒฐ๋ฆฐ๋“œ๋กฌ ๋งŒ๋“ค๊ธฐ 1254๋ฒˆ Problem 1254๋ฒˆ: ํŒฐ๋ฆฐ๋“œ๋กฌ ๋งŒ๋“ค๊ธฐ ๋™ํ˜ธ์™€ ๊ทœ์™„์ด๋Š” 212ํ˜ธ์—์„œ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•˜๊ณ  ์žˆ๋‹ค. ๊ทœ์™„์ด๋Š” ํŒฐ๋ฆฐ๋“œ๋กฌ์„ ์—„์ฒญ๋‚˜๊ฒŒ ์ข‹์•„ํ•œ๋‹ค. ํŒฐ๋ฆฐ๋“œ๋กฌ์ด๋ž€ ์•ž์—์„œ๋ถ€ํ„ฐ ์ฝ์œผ๋‚˜ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฝ์œผ๋‚˜ ๊ฐ™๊ฒŒ ์ฝํžˆ๋Š” ๋ฌธ์ž์—ด์„ ๋งํ•œ๋‹ค. ๋™ํ˜ธ๋Š” www.acmicpc.net Solution 1. ์ฃผ์–ด์ง„ ๋ฌธ์ž๋ฅผ ๋’ค์ง‘์–ด์„œ ๋’ค์— ๋ถ™์ธ๋‹ค. var str = readLine()! var newStr = (str + str.reversed()).map{String($0)} 2. ๋’ค์— ๋ถ™์ธ ๊ณณ์„ ์‹œ์ž‘์ ์œผ๋กœ ์ฃผ์–ด์ง„ ๋ฌธ์ž๊ฐ€ ๋  ๋•Œ๊นŒ์ง€ ์‚ญ์ œํ•œ๋‹ค. while newStr.count >= str.count { if isPalindrome(newStr) { min = newStr.count } if newStr.count == str.count .. 2022. 1. 6.
[Swift] Baekjoon ์ตœ๋Œ“๊ฐ’ 2562๋ฒˆ Problem 2562๋ฒˆ: ์ตœ๋Œ“๊ฐ’ 9๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ๊ณ  ๊ทธ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋กœ ๋‹ค๋ฅธ 9๊ฐœ์˜ ์ž์—ฐ์ˆ˜ 3, 29, 38, 12, 57, 74, 40, 85, 61 ์ด ์ฃผ์–ด www.acmicpc.net Solution 1. ์ˆซ์ž๋ฅผ ์ž…๋ ฅ ๋ฐ›์œผ๋ฉฐ ์ตœ๋Œ“๊ฐ’์„ ๊ฐฑ์‹ ํ•œ๋‹ค. var count:Int = 0 var max = (0,0) while count < 9 { let n = Int(readLine() ?? "") ?? 0 count += 1 if max.1 < n { max = (count,n) } } 2. ์ตœ๋Œ“๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ์ธ์ง€ ์ถœ๋ ฅํ•œ๋‹ค. print(max.1) print(max.0) Source Code 2022. 1. 6.
[Swift] Baekjoon ํฐ ์ˆ˜ A + B 10757๋ฒˆ Problem 10757๋ฒˆ: ํฐ ์ˆ˜ A+B ๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net Solution 1. ๋ฌธ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  ๊ณต๋ฐฑ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค. let line = readLine() ?? "" let lineArr = line.split(separator: " ").map{String($0)} 2. ๋‘ ๋ฌธ์ž๋ฅผ Array๋กœ ๋งŒ๋“ค๊ณ  ๋’ค์ง‘์–ด์ค€๋‹ค. var A = Array(lineArr[0].map{String($0)}.reversed()) var B = Array(lineArr[1].map{String($0)}.reversed()) 3. ๋” ๊ธด ๋ฌธ์ž๊ฐ€ ์žˆ๋‹ค๋ฉด ๋’ค์— ์ฐจ์ด๋งŒํผ 0์„ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค. var isALong = A.count > B.coun.. 2022. 1. 6.
[Swift] 2020 KAKAO BLIND RECRUITMENT ๊ฐ€์‚ฌ ๊ฒ€์ƒ‰  Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๊ฐ€์‚ฌ ๊ฒ€์ƒ‰ programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” Trie ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. (Trie ๊ด€๋ จํ•ด์„œ๋Š” ๋”ฐ๋กœ ์ •๋ฆฌํ•ด์„œ ์˜ฌ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!ใ…œ) 1. Trie ์ž๋ฃŒ ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค. ์ •์„์œผ๋กœ ๋งŒ๋“ ๊ฑด ์•„๋‹ˆ๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ๋‹จ์–ด๋ฅผ Trie ์ž๋ฃŒ๊ตฌ์กฐ์— ๋งž๊ฒŒ ์‚ฝ์ž…ํ•˜๋Š” insert ๋ฉ”์„œ๋“œ์™€ ๊ธ€์ž์˜ ์ž์‹์ด ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ์„ธ์–ด์ฃผ๋Š” getCount ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. class Node { var value:String var count:Int = 0 var children:[String:Node] = [:] init(value:String) { self.value = value } func append(_ value:String) { se.. 2022. 1. 3.
[Swift] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ง•๊ฒ€๋‹ค๋ฆฌ (with ์‰ฌ์šด ํ’€์ด ํฌํ•จ)  Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ง•๊ฒ€๋‹ค๋ฆฌ ์ถœ๋ฐœ์ง€์ ๋ถ€ํ„ฐ distance๋งŒํผ ๋–จ์–ด์ง„ ๊ณณ์— ๋„์ฐฉ์ง€์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ์‚ฌ์ด์—๋Š” ๋ฐ”์œ„๋“ค์ด ๋†“์—ฌ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ”์œ„ ์ค‘ ๋ช‡ ๊ฐœ๋ฅผ ์ œ๊ฑฐํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋„์ฐฉ์ง€์ ์ด 25๋งŒํผ ๋–จ์–ด์ ธ ์žˆ๊ณ , ๋ฐ”์œ„๊ฐ€ programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์ด์ง„ํƒ์ƒ‰์„ ์ด์šฉํ•ด์„œ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฆฌ์˜ ๊ธธ์ด n์ด๋ผ๋ฉด ์ตœ์†Œ์˜ ๊ฑฐ๋ฆฌ ์ค‘ ๊ฐ€์žฅ ํฐ ๊ฐ’์€ ๋ช‡ ์ผ๊นŒ์š”? ๋‹ค๋ฆฌ์˜ ์ค‘๊ฐ„์— ๋ฐ”์œ„๊ฐ€ ๋”ฑ ํ•œ ๊ฐœ ์žˆ์„ ๊ฒฝ์šฐ์ธ ๋‹ค๋ฆฌ ๊ธธ์ด์˜ ์ ˆ๋ฐ˜, ์ฆ‰, n/2 ์ž…๋‹ˆ๋‹ค. ๊ณ ๋กœ ๋‹ค๋ฆฌ์˜ ๊ธธ์ด์˜ ์ ˆ๋ฐ˜์ด ์ตœ์†Œ๊ฐ’ ์ค‘ ๊ฐ€์žฅ ํฐ ๊ฐ’์ด๋ผ๊ณ  ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋ฐ”์œ„๋ฅผ ์‚ญ์ œํ•ด ๋‚˜๊ฐ€๋ฉด์„œ ์ด ๊ฐ’์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ๋Š” ์˜ˆ์ œ๋กœ ์„ค๋ช…๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฆฌ์˜ ๊ธธ์ด: 25 ๋ฐ”์œ„์˜ .. 2022. 1. 3.
[Swift] 2019 KAKAO BLIND RECRUITMENT ๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ํšจ์œจ์„ฑ์ด ํ•ต์‹ฌ์ธ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. food_times๊ฐ€ ์ตœ๋Œ€ 1์–ต, k๊ฐ€ ์ตœ๋Œ€ 2*10^13์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹จ์ˆœํžˆ 0์ดˆ๋ถ€ํ„ฐ ์‹œ๊ฐ„์„ ์žฌ๋ฉฐ ์Œ์‹์„ ํ™•์ธํ•˜๊ธฐ์—” ๋„ˆ๋ฌด ํฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค. 1. ์Œ์‹์ด ๋‚จ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋ฅผ ์ •์˜ํ•œ๋‹ค. ์Œ์‹์„ ๋จน๋Š” ์‹œ๊ฐ„์„ ๋ชจ๋‘ ํ•ฉ์ณ๋„ k๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด k์‹œ๊ฐ„์— ๋‚จ๋Š” ์Œ์‹์ด ์—†์Šต๋‹ˆ๋‹ค. if food_times.reduce(0,+) $1.element} 3. ๋‚จ์€ ์Œ์‹ ์ˆ˜์™€ ์ตœ์†Œ ์‹œ๊ฐ„์„ ๊ณฑํ•˜์—ฌ k์—์„œ ๋นผ์ค€๋‹ค. ํ•œ๋ฒˆ์— ์Œ์‹ ์ˆ˜๋ฅผ ๊ฐ€์žฅ ๋งŽ์ด ๋บ„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ํ˜„์žฌ ๋‚จ์€ ์Œ์‹ ์ˆ˜์™€ ๊ฐ€์žฅ ์ตœ์†Œ๊ฐ’์„ ๊ณฑํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰, [3,5,6,7,8,9,4,4,3,3]๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด ํ˜„์žฌ ๋‚จ์€ .. 2021. 12. 15.
728x90
๋ฐ˜์‘ํ˜•