Post

๐Ÿน ์นด๋“œ ์„ž๊ธฐ

1. ๋ฌธ์ œ ๋งํฌ

21315๋ฒˆ: ์นด๋“œ ์„ž๊ธฐ


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.