๊ธ€ ์ž‘์„ฑ์ž: ๊ฐœ๋ฐœํ•˜๋Š” ํ›ˆ์ด

๋ฌธ์ œ

๋ฌธ์ œ ์„ค๋ช…

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํŒ€์—์„œ๋Š” ๊ธฐ๋Šฅ ๊ฐœ์„  ์ž‘์—…์„ ์ˆ˜ํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค. ๊ฐ ๊ธฐ๋Šฅ์€ ์ง„๋„๊ฐ€ 100%์ผ ๋•Œ ์„œ๋น„์Šค์— ๋ฐ˜์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜, ๊ฐ ๊ธฐ๋Šฅ์˜ ๊ฐœ๋ฐœ์†๋„๋Š” ๋ชจ๋‘ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋’ค์— ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ์•ž์— ์žˆ๋Š” ๊ธฐ๋Šฅ๋ณด๋‹ค ๋จผ์ € ๊ฐœ๋ฐœ๋  ์ˆ˜ ์žˆ๊ณ , ์ด๋•Œ ๋’ค์— ์žˆ๋Š” ๊ธฐ๋Šฅ์€ ์•ž์— ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ๋ฐฐํฌ๋  ๋•Œ ํ•จ๊ป˜ ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค.

๋จผ์ € ๋ฐฐํฌ๋˜์–ด์•ผ ํ•˜๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ž‘์—…์˜ ์ง„๋„๊ฐ€ ์ ํžŒ ์ •์ˆ˜ ๋ฐฐ์—ด progresses์™€ ๊ฐ ์ž‘์—…์˜ ๊ฐœ๋ฐœ ์†๋„๊ฐ€ ์ ํžŒ ์ •์ˆ˜ ๋ฐฐ์—ด speeds๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ ๋ฐฐํฌ๋งˆ๋‹ค ๋ช‡ ๊ฐœ์˜ ๊ธฐ๋Šฅ์ด ๋ฐฐํฌ๋˜๋Š”์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜์„ธ์š”.

 

์ œํ•œ ์‚ฌํ•ญ

  • ์ž‘์—…์˜ ๊ฐœ์ˆ˜(progresses, speeds๋ฐฐ์—ด์˜ ๊ธธ์ด)๋Š” 100๊ฐœ ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • ์ž‘์—… ์ง„๋„๋Š” 100 ๋ฏธ๋งŒ์˜ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • ์ž‘์—… ์†๋„๋Š” 100 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • ๋ฐฐํฌ๋Š” ํ•˜๋ฃจ์— ํ•œ ๋ฒˆ๋งŒ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ•˜๋ฃจ์˜ ๋์— ์ด๋ฃจ์–ด์ง„๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ง„๋„์œจ์ด 95%์ธ ์ž‘์—…์˜ ๊ฐœ๋ฐœ ์†๋„๊ฐ€ ํ•˜๋ฃจ์— 4%๋ผ๋ฉด ๋ฐฐํฌ๋Š” 2์ผ ๋’ค์— ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

ํ’€์ด

๊ตฌํ˜„ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ์ž‘์—…์„ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด๊ฐ€๋ฉด์„œ ํ•ด๋‹น ์ž‘์—…์ด ์™„์ „ํžˆ ๋๋‚˜๋Š” ์‹œ๊ฐ„ ๋‚ด์— ๊ฐ™์ด ๋๋‚˜๋Š” ์ž‘์—…๋“ค์„ ๋ชฉ๋ก์—์„œ ๋นผ์ค๋‹ˆ๋‹ค.

์ฝ”๋“œ

import Foundation

func finishJob (_ progresses : inout [Int], _ speeds: inout [Int]) -> Int{
    progresses.removeFirst()
    speeds.removeFirst()
    return 1
}

func calcDaysLeft (_ progresses : inout [Int], _ speeds: inout [Int]) -> Int {
    let funcNow = progresses.first!
    let timeLeft = 100 - funcNow
    
    return Int(ceil(Double(timeLeft) / Double(speeds.first!)))
}

func solution(_ progresses:[Int], _ speeds:[Int]) -> [Int] {
    var progs = progresses
    var spds = speeds
    var answer : [Int] = []
    
    while(!progs.isEmpty) {
        var finishCount = 0
        let currFuncDaysLeft = calcDaysLeft(&progs, &spds)
        finishCount += finishJob(&progs, &spds)
        
        for _ in 0..<progs.count {
            let nextFuncDaysLeft = calcDaysLeft(&progs, &spds)
            if (currFuncDaysLeft >= nextFuncDaysLeft) {
                finishCount += finishJob(&progs, &spds)
            }
        }
        answer.append(finishCount)
    }
    return answer
}