Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 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||
--
| 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|
---
20 changes: 20 additions & 0 deletions alstjr7437/ํˆฌํฌ์ธํ„ฐ/BOJ_7795.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let T = Int(readLine()!)!

for _ in 0..<T {
let NM = readLine()!.split(separator: " ").map { Int($0)! }
let A = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
let B = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
Comment on lines +1 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•ˆ๋…•ํ•˜์„ธ์š” ์ œ ์ž…๋ ฅ๋ถ€๋„ ํ‰๊ฐ€ํ•ด์ฃผ์„ธ์š”~

import Foundation

guard let T = Int(readLine() ?? "") else { exit(0) }

var result: [Int] = []

// ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ
(0..<T).forEach { caseNumber in
    guard let AandB = readLine()?.split(separator: " "),
          let N = Int(AandB[0]),
          let M = Int(AandB[1]) else { exit(0) }
    
    guard let lineA = readLine() else { exit(0) }
    let A = lineA.split(separator: " ").compactMap { Int($0) }
    guard A.count == N else { exit(0) }
    
    guard let lineB = readLine() else { exit(0) }
    let B = lineB.split(separator: " ").compactMap { Int($0) }
    guard B.count == M else { exit(0) }
    
    result.append(eatPairs(A, B))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giljihun ๊ธธ!!!!! ์บฌ ...... AandB ์นด๋ฉœํˆฌํƒ‘๋ด‰์˜ค๋ฆฌ์ผ€์ด์Šจ๊ฐ€์˜ˆ ์ง์ด๋„ค์˜ˆ !

compactmap ํ™œ์šฉ๊นŒ์ง€ ... ์™€์šฐ !! ์™€ ๊ทผ๋ฐ ํˆฌํฌ์ธํ„ฐ ์ƒ๊ฐ์€ ํ•ด๋„ ๋ฐ”๋กœ ๊ตฌํ˜„์ด ์‰ฝ์ง€ ์•Š์€๋ฐ ๋ฉ‹์ง‘๋‹ˆ๋‹ค


var point = 0
var result = 0
for i in A {
result += point
for j in point..<B.count {
if i > B[j] {
point = j + 1
result += 1
Comment on lines +8 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???? ์ด๋ ‡๊ฒŒ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ’€ ์ˆ˜๋„ ์žˆ๊ตฐ์š”... ํˆฌํฌ์ธํ„ฐ๋ฅผ ํ™œ์šฉํ•ด๋ณธ ์ ์ด ์—†์–ด์„œ ์ด๋ถ„ํƒ์ƒ‰์œผ๋กœ ํ–ˆ๋Š”๋ฐ ์ž˜ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!

Copy link
Collaborator

@YooGyeongMo YooGyeongMo May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2025-05-06 แ„‹แ…ฉแ„’แ…ฎ 5 22 48

์ฑ— ์‰จํ•œํ…Œ ์ €๋„ ๋ฌด๊บผ ๋ณด๊ณ  ์ •๋ฆฌํ•ด๋‹ฌ๋ผํ–ˆ๋Š”๋ฐ ํ•ญ์ƒ ์ž…๋ ฅ๊ฐ’ ๋ณด๊ณ  ์™„ํƒ์„ ํ• ์ง€ ์•ˆํ• ์ง€ ๋”ฑ ์•Œ๋ ค์คฌ์Œํ•ด์„œ ์ฐธ๊ณ ์ž๋ฃŒ ์ฒจ๋ถ€ํ•ด๋ด…๋‹ˆ๋‹ค ํ•˜์ง€๋งŒ ์ทŸ์‰‘์ด๋ผ์„œ ๊ฒ€์ฆ์ด ์•ˆ๋œ๊ฒƒ์ด๋‹ˆ ์ €ํฌ๋ผ๋ฆฌ ์‹œํ–‰์ฐฉ์˜ค๋ฅผ ๊ฒช์–ด๊ฐ€๋ฉฐ ์ข€ ๋” ์—…๋ฐ์ดํŠธํ•ด๋ณด๋Š”๊ฒƒ๋„ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2๋งŒ์ด ๋ณด์ด๋ฉด ์™„ํƒ์ด ๋ญ”๊ฐ€ ์•ˆ๋œ๋‹ค๋Š” ์••๋ฐ•์ด ๋А๊ปด์ ธ์„œ ํ–ˆ๋Š”๋ฐ ์ž˜ ๋œ ๊ฒƒ ๊ฐ™๋„ค์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

}
}
}
Comment on lines +10 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ์—„์ฒญ ๊น”๋”ํ•˜๋„ค์š”.. ๐Ÿ‘ ์ €๋Š” ์ข€ ๊ณ ๊ตฐ๋ถ„ํˆฌํ•˜๋‹ค๋ณด๋‹ˆ๊นŒ ๊ฐ™์€ ๋กœ์ง์ธ๋ฐ๋„ ์ข€ ๋‚œ์žกํ•œ ๊ฐ์ด ์žˆ๋„ค์š”..
๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ท

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ•€์Œค ์ปค์„œ ์“ฐ์…”์„œ ๊ทธ๋Ÿฐ์ง€ ๋ณ€์ˆ˜๋ช…์„ ์ปค์„œ๋กœ ํ•˜์…จ๊ตฐ์š”.
aItem ํ˜น์€ bIdx ๊ฐ™์€ ๋ณ€์ˆ˜๋ช…์ด๋‚˜ ์ธ๋ฑ์Šค ๋ช…๋“ค์ด ์ €๋Š” ๊ฐ€๋” ๊ฐ€๋…์„ฑ์ด ๋‚ฎ๋‹ค๊ณ  ํŒ๋‹จ๋  ๋•Œ๊ฐ€ ์žˆ๋Š”๋ฐ ํ•€์Œค๊ณผ ํ‚จ๋”์Œค ํ˜น์€ ์—ฌ๋Ÿฌ๋ถ„๋“ค์€ ์–ด๋– ์‹ ๊ฐ€์š” ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งž์•„์š” ํ•œ๋ฒˆ์”ฉ ํ–‡๊ฐˆ๋ ค์„œ ๋‹ค๋ฅธ ์ข‹์€ ๋ณ€์ˆ˜๋ช… ์ฐพ์œผ๋ฉด์„œ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ๊ฒฐ๊ตญ ์ต์ˆ™ํ•œ ๊ณณ์œผ๋กœ ๋Œ์•„์˜ค๊ฒŒ ๋˜๋”๋ผ๊ตฌ์š” ใ… ..

print(result)
}
Comment on lines +10 to +20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฝ”๋“œ๊ฐ€ ๋˜๊ฒŒ ๊น”๋”ํ•˜๋„ค์š” ,, ํฌ์ธํ„ฐ๊ฐ€ ๋‘๊ฐœ๋กœ ๋˜๋ฉด A๋งŒํผ B๋งŒํผ ๊ฐ๊ฐ ์‹œ๊ฐ„ ๋ณต์žก๋„ ๊ฐ€์ง€๋‹ˆ O(N+M)๋งŒํผ ๊ฐ€์ง€๋Š”๊ฒŒ ๋งž์„๊นŒ์š” ???

์•Œ์•„๋ณด๋‹ˆ sorted๋Š” N(LogN) ์ด๋„ค์š”!!

๊ฒฐ๊ตญ ์™„ํƒ์—์„œ ๋ฐœ์ „ํ•ด์„œ ํˆฌํฌ์ธํ„ฐ๋กœ ํ’€๋ฉด ๋˜๋Š” ๋ฌธ์ œ์˜€๊ตฐ์š” ! ์ €๋Š” ์ด์ง„ ํƒ์ƒ‰์œผ๋กœ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค !!

import Foundation

let T = Int(readLine()!)!

for _ in 0..<T {
    let nm = readLine()!.split(separator: " ").map {Int($0)!}
    let N = nm[0], M = nm[1]
    
    let A = readLine()!.split(separator:" ").map { Int($0)!}
    let B = readLine()!.split(separator:" ").map { Int($0)!}.sorted()
    
    var count = 0
    for found in A {
        count += check(B, found)
    }
    print(count)
}
// 8 1 7 3 1
// 1 3 6
// 0  < 3
// mid = 1
// arr[1] = 3 < 4
// left = 2
// 2 < 3
// mid = 2
// arr[2] 6 < 4
// right = 2
// left == 2 , right == 2
// left -> 2
func check(_ arr: [Int], _ target: Int) -> Int {
    var left = 0
    var right = arr.count
    
    while left < right {
        let mid = (left + right) / 2
        if arr[mid] < target {
            left = mid + 1
        } else {
            right = mid
        }
    }
    return left
}

์ง์ ‘ ๋น„๊ตํ•˜๋‹ˆ ๋” ์ข‹๊ตฐ์š” ! ํˆฌ ํฌ์ธํ„ฐ๋„ ์—ฐ์Šตํ•ด์•ผ๊ฒ ์–ด์š” !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ ์ด์ง„ ํƒ์ƒ‰์€ ์ƒ๊ฐ ๋ชปํ–ˆ์—ˆ๋Š”๋ฐ ์ด์ง„ ํƒ์ƒ‰์œผ๋กœ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋„ค์š” ์ข‹๋„ค์š”!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alstjr7437 ๊ณ ์ˆ˜์˜ ํ–ฅ๊ธฐ ํ‚จ๋” .... ๊ทธ์˜ ์ฝ”๋“œ๋Š” ํด๋ฆฐ์ฝ”๋“œ์˜€๋‹ค... ์บฌ ~