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

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 20546๋ฒˆ - ๊ธฐ์ ์˜ ๋งค๋ฏธ๋ฒ• (๊ตฌํ˜„)

๊ฐ์ž ๐Ÿฅ” 2023. 2. 15. 23:28
๋ฐ˜์‘ํ˜•

๐ŸŸ  ๋ฌธ์ œ

 

๐ŸŸ  ๋‚˜์˜ ํ’€์ด

๋ฌธ์ œ๋Š” ๋˜๊ฒŒ ์œผ๋ฆฌ์œผ๋ฆฌ ํ•˜์ง€๋งŒ, ์‹ค๋ฒ„ 5๋ฐ–์— ๋˜์ง€ ์•Š๋Š” ๊ทธ๋ƒฅ ๊ตฌํ˜„ ๋ฌธ์ œ!
์กฐ๊ฑด๋งŒ ์ž˜ ๋”ฐ๋ผ์„œ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด์ฃผ๋ฉด ๋์ด๋‹ค. 

๊ทผ๋ฐ ์™œ ํ‹€๋ ธ๋ƒ๊ณ ? ๋‚œ์ด๋„ ๋‚ฎ์€ ๋ฌธ์ œ ํ‹€๋ฆฌ๋ฉด ์™ค์ผ€ ํ™”๊ฐ€๋‚ ๊นŒ ใ…Žใ…Žํ•˜ํ•˜ํ•˜ํ•˜

์˜ˆ์ „ ํ•™์ฐฝ์‹œ์ ˆ์—๋„ ๋ฌธ์ œ๋ฅผ ์ œ๋Œ€๋กœ ์ฝ์ง€ ์•Š์•„์„œ '์•Š์€'๊ฒƒ์„ ๊ณ ๋ฅด๋ผ๊ณ  ํ–ˆ๋Š”๋ฐ ์˜ณ์€ ๊ฒƒ์„ ๊ณ ๋ฅด๊ณค ํ–ˆ๋‹ค. ๊ทผ๋ฐ,,, ์ง€๊ธˆ๋„ ๋‹จ์ˆœํžˆ ์˜ˆ์ œ์—์„œ BNP ์•„๋‹ˆ๋ฉด TIMING๋งŒ ์ฃผ์–ด์กŒ๋‹ค๊ณ  ๊ฐ™์„๊ฒฝ์šฐ์˜ ์กฐ๊ฑด์„ ์ฒ˜๋ฆฌํ•ด์ฃผ์ง€ ์•Š์•˜๋”ฐ ํ•˜ํ•˜ํ•˜ํ•˜ํ•˜ํ•˜ํ•˜

๋ถ„๋ช… ์ด๋ ‡๊ฒŒ ์ถœ๋ ฅํ•˜๋ผ๊ณ  ํ–ˆ๋Š”๋ฐ ๋ง์ด๋‹ค ^0^/ ๐ŸŽถ ์„ธ๋ฒˆ๋งŒ์— ๋ฐœ๊ฒฌํ•˜๊ณ , ์กฐ๊ฑด์ฒ˜๋ฆฌํ•ด์ค˜์„œ ํ†ต๊ณผ......ํ–ˆ๋‹ค.....

โœจ ๊ฒฐ๋ก !!  ๋ฌธ์ œ๋ฅผ ์ž˜์ฝ๊ณ , ๋ฌธ์ œ์กฐ๊ฑด ๋ฐ ์ถœ๋ ฅ์กฐ๊ฑด์„ ํ•ญ์ƒ ํ™•์ธํ•˜์ž

๐ŸŸ  ์ •๋‹ต์ฝ”๋“œ

import Foundation

let money = Int(readLine()!)!
let arr = [-1] + readLine()!.split(separator: " ").map{ Int($0)! }

private func bnp(_ money: Int) -> Int {
    var cash = money
    var cnt = 0

    for i in 1..<arr.count {
        if cash >= arr[i] {
            cnt += cash / arr[i]
            cash -= (cash / arr[i]) * arr[i]
        }
    }
    return cnt * arr[14] + cash
}

private func timing(_ money: Int) -> Int {
    var cash = money
    var cnt = 0
    
    for i in 4..<arr.count {
        if arr[i-3] < arr[i-2], arr[i-2] < arr[i-1], arr[i-1] < arr[i] {
            if cnt > 0 {
                cash += arr[i] * cnt
                cnt = 0
            }
        } else if arr[i-3] > arr[i-2], arr[i-2] > arr[i-1], arr[i-1] > arr[i] {
            if cash >= arr[i] {
                cnt += cash / arr[i]
                cash -= (cash / arr[i]) * arr[i]
            }
        }
    }
    return cnt * arr[14] + cash
}

if bnp(money) == timing(money) {
    print("SAMESAME")
} else {
    bnp(money) > timing(money) ? print("BNP") : print("TIMING")
}

 

๋ฐ˜์‘ํ˜•