Skip to content

Commit 66e86d7

Browse files
committed
[BOJ] #14713. 앵무새 / 실버1 / 30분 / 힌트
1 parent 6c7d876 commit 66e86d7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
from collections import deque
3+
4+
input = sys.stdin.readline
5+
6+
N = int(input()) # 앵무새 수
7+
S = [] # 앵무새 문장
8+
for _ in range(N):
9+
S.append(deque(input().split()))
10+
L = deque(input().split()) # 받아 적은 문장
11+
12+
while L:
13+
current = L.popleft() # 현재 단어
14+
found = False
15+
16+
# 각 앵무새 문장에서 단어 찾기
17+
for s in S:
18+
if s and s[0] == current: # 매칭되는 단어가 있다면
19+
s.popleft() # 단어 제거
20+
found = True
21+
break
22+
23+
if not found: # 매칭되는 단어가 없으면 Impossible
24+
print("Impossible")
25+
exit()
26+
27+
# 모든 문장이 비었는지 확인
28+
if any(s for s in S): # S에 남은 문장이 있다면 Impossible
29+
print("Impossible")
30+
else:
31+
print("Possible")

0 commit comments

Comments
 (0)