-
Notifications
You must be signed in to change notification settings - Fork 0
3-alstjr7437 #17
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
3-alstjr7437 #17
Changes from all commits
9b3dee7
7ca30f9
5ace76b
8d36215
03abe1a
bac1e67
ac522b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() | ||
|
|
||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ???? ์ด๋ ๊ฒ ๊ฐ๊ฒฐํ๊ฒ ํ ์๋ ์๊ตฐ์... ํฌํฌ์ธํฐ๋ฅผ ํ์ฉํด๋ณธ ์ ์ด ์์ด์ ์ด๋ถํ์์ผ๋ก ํ๋๋ฐ ์ ๋ฐฐ์๊ฐ๋๋ค!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฑ ์จํํ ์ ๋ ๋ฌด๊บผ ๋ณด๊ณ ์ ๋ฆฌํด๋ฌ๋ผํ๋๋ฐ ํญ์ ์ ๋ ฅ๊ฐ ๋ณด๊ณ ์ํ์ ํ ์ง ์ํ ์ง ๋ฑ ์๋ ค์คฌ์ํด์ ์ฐธ๊ณ ์๋ฃ ์ฒจ๋ถํด๋ด ๋๋ค ํ์ง๋ง ์ท์์ด๋ผ์ ๊ฒ์ฆ์ด ์๋๊ฒ์ด๋ ์ ํฌ๋ผ๋ฆฌ ์ํ์ฐฉ์ค๋ฅผ ๊ฒช์ด๊ฐ๋ฉฐ ์ข ๋ ์ ๋ฐ์ดํธํด๋ณด๋๊ฒ๋ ์ข์๋ณด์ ๋๋ค.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2๋ง์ด ๋ณด์ด๋ฉด ์ํ์ด ๋ญ๊ฐ ์๋๋ค๋ ์๋ฐ์ด ๋๊ปด์ ธ์ ํ๋๋ฐ ์ ๋ ๊ฒ ๊ฐ๋ค์ ๊ฐ์ฌํฉ๋๋ค! |
||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+10
to
+18
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ ์์ฒญ ๊น๋ํ๋ค์.. ๐ ์ ๋ ์ข ๊ณ ๊ตฐ๋ถํฌํ๋ค๋ณด๋๊น ๊ฐ์ ๋ก์ง์ธ๋ฐ๋ ์ข ๋์กํ ๊ฐ์ด ์๋ค์..
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ์ค ์ปค์ ์ฐ์
์ ๊ทธ๋ฐ์ง ๋ณ์๋ช
์ ์ปค์๋ก ํ์
จ๊ตฐ์.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ง์์ ํ๋ฒ์ฉ ํ๊ฐ๋ ค์ ๋ค๋ฅธ ์ข์ ๋ณ์๋ช ์ฐพ์ผ๋ฉด์ ๊ณ ๋ฏผํ๋ค๊ฐ ๊ฒฐ๊ตญ ์ต์ํ ๊ณณ์ผ๋ก ๋์์ค๊ฒ ๋๋๋ผ๊ตฌ์ ใ .. |
||
| print(result) | ||
| } | ||
|
Comment on lines
+10
to
+20
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
}
์ง์ ๋น๊ตํ๋ ๋ ์ข๊ตฐ์ ! ํฌ ํฌ์ธํฐ๋ ์ฐ์ตํด์ผ๊ฒ ์ด์ !
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์คํธ ์ด์ง ํ์์ ์๊ฐ ๋ชปํ์๋๋ฐ ์ด์ง ํ์์ผ๋ก ํ๋ ๋ฐฉ๋ฒ๋ ์๋ค์ ์ข๋ค์!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alstjr7437 ๊ณ ์์ ํฅ๊ธฐ ํจ๋ .... ๊ทธ์ ์ฝ๋๋ ํด๋ฆฐ์ฝ๋์๋ค... ์บฌ ~ |
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ํ์ธ์ ์ ์ ๋ ฅ๋ถ๋ ํ๊ฐํด์ฃผ์ธ์~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giljihun ๊ธธ!!!!! ์บฌ ...... AandB ์นด๋ฉํฌํ๋ด์ค๋ฆฌ์ผ์ด์จ๊ฐ์ ์ง์ด๋ค์ !
compactmap ํ์ฉ๊น์ง ... ์์ฐ !! ์ ๊ทผ๋ฐ ํฌํฌ์ธํฐ ์๊ฐ์ ํด๋ ๋ฐ๋ก ๊ตฌํ์ด ์ฝ์ง ์์๋ฐ ๋ฉ์ง๋๋ค