๐น ์นด๋ ์๊ธฐ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
PyPy3
208848KB
2860ms
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
from itertools import product
def shuffle(k):
global cards
# 1๋จ๊ณ ์๊ธฐ
left = cards[:N-2**k]
main_cards = cards[N-2**k:]
# ๋๋จธ์ง ์๊ธฐ
for i in range(2, k + 2):
l = len(main_cards)
left = main_cards[:l-2**(k-i+1)] + left
main_cards = main_cards[l-2**(k-i+1):]
return main_cards + left
N = int(input())
end_cards = list(map(int, input().split()))
k_cases = [i for i in range(1, N+1)]
for first, second in product(k_cases, repeat=2):
cards = [i for i in range(1, N+1)]
cards = shuffle(first)
cards = shuffle(second)
if cards == end_cards:
print(first, second)
break
3. ํด์ค
ํ ๋ฒ ์นด๋๋ฅผ ์์ ๋๋ง๋ค ๊ฐ์ฅ ์ต๊ทผ์ ์์ ์นด๋ ๋ฒ์๋ฅผ main_cards์ ์ ์ฅํด ๋ ํ ๋จ์ ์นด๋๋ค์ ๋จ๊ฒจ์ค ์์๋๋ก ํฉ์น๋ค. (์ด๋ ๋จ๊ฒจ์ง ์์๊ฐ ์ค๋ ๋ ์์์ผ ์๋ก ๋ค์ชฝ์ ์๋ฆฌํ๋ค)
1๋ถํฐ N๊น์ง์ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ์ค๋ณต์์ด๋ก ์ฒ๋ฆฌํ์ฌ ๋ ๋ฒ ์๋ ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ๊ตฌํ๋ค.
๋ชจ๋ ๊ฒฝ์ฐ๋ก 2๋ฒ ์์ด๋ณธ ํ ์ต์ข ์นด๋ ์์๊ฐ ๋์ผํ ๊ฒฝ์ฐ์ k๋ฅผ ์ถ๋ ฅํ๋ค.
This post is licensed under CC BY 4.0 by the author.