Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] 랭킹전 대기열 #207

Closed
hwangJi-dev opened this issue Apr 20, 2023 · 0 comments
Closed

[Algorithm] 랭킹전 대기열 #207

hwangJi-dev opened this issue Apr 20, 2023 · 0 comments
Assignees

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Apr 20, 2023

💬 문제

https://www.acmicpc.net/problem/20006


💬 Idea

  • roomArr를 돌면서 만약 입장할 수 있는 방이 있다면 방이 시작한 순서대로 입장시키기 위해 방을 배열에 저장한다.
  • 입장할 수 있는 방이 있다면 입장시킨 후 반복문을 break하고,
  • 입장할 수 있는 방이 없다면 새로운 방을 생성한다.

💬 풀이

func solution200006() {
    let pm = readLine()!.split(separator: " ").map({ Int(String($0))! })
    var roomArr: [(Int, Int)] = []
    var roomInfo: [Int: [(Int, String)]] = [:]
    
    for _ in 0..<pm[0] {
        let p = readLine()!.split(separator: " ").map({ String($0) })
        let level = Int(p[0])!
        let id = p[1]
        var room = -1
        
        for (idx, r) in roomArr.enumerated() {
            if level >= r.0 && level <= r.1 && roomInfo[idx]!.count < pm[1] {
                room = idx
                roomInfo[idx]!.append((level, id))
                break
            }
        }
        
        if room == -1 {
            // 새로운 방 생성
            roomArr.append((level - 10, level + 10))
            roomInfo[roomArr.count - 1] = [(level, id)]
        }
    }
    
    for (idx, _) in roomArr.enumerated() {
        if roomInfo[idx]!.count == pm[1] {
            print("Started!")
        } else {
            print("Waiting!")
        }
        
        for j in roomInfo[idx]!.sorted(by: { $0.1 < $1.1 }) {
            print("\(j.0) \(j.1)")
        }
    }
}

소요시간 : 29분

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant