Skip to content

Instantly share code, notes, and snippets.

@dongwooklee96
Created May 29, 2021 13:10
Show Gist options
  • Save dongwooklee96/a85641fe2a9b2fa41fec0d67ff0f3aa9 to your computer and use it in GitHub Desktop.
Save dongwooklee96/a85641fe2a9b2fa41fec0d67ff0f3aa9 to your computer and use it in GitHub Desktop.
def solve(real_list, dream_list):
real_cnt = len(real_list)
dream_cnt = len(dream_list)
max_level_cnt = (dream_cnt - real_cnt) // (real_cnt - 1)
# 첫번째 원소를 구한다.
first_elem = real_list[0]
first_elem_idx_list = []
min_max = []
for elem in real_list:
if elem not in dream_list:
return -1
# 꿈에서 첫 번째 원소가 일치하는 것을 모두 구한다.
for idx, elem in enumerate(dream_list):
if first_elem == elem:
first_elem_idx_list.append(idx)
for level in range(max_level_cnt, 0, -1):
for first_elem_idx in first_elem_idx_list:
tot = 1
for cnt in range(1, real_cnt):
cnt_ = first_elem_idx + ((level + 1) * cnt)
if cnt_ >= dream_cnt:
continue
if dream_list[cnt_] == real_list[cnt]:
tot += 1
if tot == real_cnt:
min_max.append(level)
if min_max:
return min(min_max), max(min_max)
elif len(min_max) == 1:
return min(min_max)
return 0, 0
if __name__ == '__main__':
input()
real_list = list(map(int, input().split()))
input()
dream_list = list(map(int, input().split()))
print(solve(real_list, dream_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment