B - The Honest Woodcutters 解説 by en_translator
Original proposer: vwxyz
Axe \(i\) was owned by woodcutter \(B_i\), who claims that they originally owned axe \(A_{B_i}\).
Therefore, woodcutter \(B_i\)’s claim is true if and only if \(A_{B_i}=i\).
By the constraints, each of \(1,2,\dots,N\) occurs exactly once in \(B_1,B_2,\dots,B_N\).
Therefore, it is sufficient to check if \(A_{B_i}=i\) for each \(i\).
The time complexity is \(O(N)\).
When the answer to this problem is Yes, \(A\) and \(B\) are said the inverse of each other.
When \(A\) and \(B\) are length-\(N\) permutations, we have:
\(A\) is the inverse of \(B\)
\(\Leftrightarrow\) \(B\) is the inverse of \(A\)
\(\Leftrightarrow\) \(A_{B_i}=i\) for all \(i\)
\(\Leftrightarrow\) \(B_{A_i}=i\) for all \(i\).
投稿日時:
最終更新: