はまやんはまやんはまやん

hamayanhamayan's blog

Permutation Cycle [ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) C]

http://codeforces.com/contest/932/problem/C

f(i,j) := P[i] (j=1)
f(i,j) := f(P[i], j-1) (otherwise)
と定義される関数fがある。
関数g(i)をf(i,j)=iとなる最小のjと定義する。
g(1), g(2), ..., g(N)の値がAかBのいずれかになるように順列Pを構築せよ。
不可能なら"-1"

続きを読む