nokoのブログ

こちらは暫定のメモ置き場ですので悪しからず

ABC150-C_CountOrderをpythonで解いた(順列)

問題

ポイント

  • 順列の要素の洗い出し
n = 3
for permutations_i in itertools.permutations((range(1, n+1))):
    print(permutations_i)
# 実行結果
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)

解法

n=int(input())
p_list = tuple(list(map(int,input().split())))
q_list = tuple(list(map(int,input().split())))

import itertools
count = 0

for permutations_i in itertools.permutations((range(1, n+1))):
    count += 1
    if permutations_i == p_list:
        count_p = count
    if permutations_i == q_list:
        count_q = count

print(abs(count_p - count_q))

感想

  • ABC150のDは問題に不備があったとかなんとかだったのでCを載せます。