From 38de3906eecca4792bce3aecf5dc6484a36095aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Tue, 13 May 2025 01:03:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=204=EC=B0=A8=EC=8B=9C=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alstjr7437/README.md | 3 +- .../\352\265\254\355\230\204/BOJ_1713.swift" | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 "alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" diff --git a/alstjr7437/README.md b/alstjr7437/README.md index ace1a9b..035553e 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -4,5 +4,6 @@ |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2025.03.26 | BFS | [미로 탐색](https://www.acmicpc.net/problem/2178)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/2| | 2차시 | 2025.04.08 | Heap | [최대힙](https://www.acmicpc.net/problem/11279)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/7| -| 3차시 | 2025.04.30 | 투포인터 | [최대힙](https://www.acmicpc.net/problem/7795)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/17| +| 3차시 | 2025.04.30 | 투포인터 | [먹을 것인가 먹힐 것인가](https://www.acmicpc.net/problem/7795)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/17| +| 4차시 | 2025.05.13 | 구현 | [후보 추천하기](https://www.acmicpc.net/problem/1713)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/24| --- diff --git "a/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" "b/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" new file mode 100644 index 0000000..9e46e9d --- /dev/null +++ "b/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" @@ -0,0 +1,29 @@ +let N = Int(readLine()!)! +let totalCount = Int(readLine()!)! +let recommend = readLine()!.split(separator: " ").map { Int(String($0))! } + +var result: [Int: (recommendCount: Int, time: Int)] = [:] +var currentTime = 0 + +for student in recommend { + if result[student] != nil { + result[student]!.recommendCount += 1 + } else { + if result.count < N { + result[student] = (1, currentTime) + } else { + let removeValue = result.min { + if $0.value.recommendCount == $1.value.recommendCount { + return $0.value.time < $1.value.time + } + return $0.value.recommendCount < $1.value.recommendCount + }!.key + + result.removeValue(forKey: removeValue) + result[student] = (1, currentTime) + } + } + currentTime += 1 +} + +print(result.keys.sorted().map { String($0) }.joined(separator: " "))