-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10815.py
74 lines (51 loc) · 2.11 KB
/
10815.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# [ 백준 ] 10815반: 숫자 카드
def solution() -> None:
import sys
input = sys.stdin.readline
N: int = int(input())
cards: list[int] = sorted(list(map(int, input().split())))
M: int = int(input())
for target in list(map(int, input().split())):
flag: int = 0
start, end = 0, N-1
while start <= end:
middle = (start + end) // 2
card = cards[middle]
if target == card:
flag = 1
break
elif target < card:
end = middle - 1
else:
start = middle + 1
print(flag, end=" ")
def another_solution() -> None:
import sys
import bisect
input = sys.stdin.readline
N: int = int(input())
cards: list[int] = sorted(list(map(int, input().split())))
M: int = int(input())
for target in list(map(int, input().split())):
left_value = bisect.bisect_left(a=cards, x=target)
right_value = bisect.bisect_right(a=cards, x=target)
print(0, end=" ") if not(right_value - left_value) else print(1, end=" ")
if __name__ == "__main__":
from io import StringIO
from unittest.mock import patch
def test_example_case(input: list[str]) -> str:
with patch("sys.stdin.readline", side_effect=input):
with patch("sys.stdout", new_callable=StringIO) as test_stdout:
solution()
return test_stdout.getvalue()
def test_another_solution(input: list[str]) -> str:
with patch("sys.stdin.readline", side_effect=input):
with patch("sys.stdout", new_callable=StringIO) as test_stdout:
another_solution()
return test_stdout.getvalue()
case: dict[str, list[str] | str] = {
"input": ['5', "6 3 2 10 -10", '8', "10 9 -5 2 3 4 5 -10"],
"output": "1 0 0 1 1 0 0 1 "
}
assert case["output"] == test_example_case(input=case["input"])
assert case["output"] == test_another_solution(input=case["input"])