-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj_01920.swift
35 lines (28 loc) · 903 Bytes
/
boj_01920.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 2022.04.01
// Dongyoung Kwon @Chuncheonian (ehddud2468@gmail.com)
// https://www.acmicpc.net/problem/1920
func binarySearch(arr: [Int], target: Int) -> Int {
var (start, end) = (0, arr.count - 1)
while start <= end {
let mid = (start + end) / 2
if arr[mid] == target {
return 1
} else if arr[mid] < target {
start = mid + 1
} else {
end = mid - 1
}
}
return 0
}
let _ = Int(readLine()!)!
let a = readLine()!.split{ $0 == " "}.map{ Int(String($0))! }.sorted()
let _ = readLine()!
readLine()!.split{ $0 == " " }.map{ Int(String($0))! }.forEach{ print(binarySearch(arr: a, target: $0)) }
// 시간초과
// let _ = readLine()!
// let a = readLine()!.components(separatedBy: " ")
// let _ = readLine()!
// for char in readLine()!.components(separatedBy: " ") {
// print(a.contains(char) ? 1 : 0)
// }