結果
| 問題 | 
                            No.2254 Reverse Only
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 21:18:26 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,039 bytes | 
| コンパイル時間 | 166 ms | 
| コンパイル使用メモリ | 82,148 KB | 
| 実行使用メモリ | 160,612 KB | 
| 最終ジャッジ日時 | 2025-06-12 21:18:39 | 
| 合計ジャッジ時間 | 9,879 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 30 WA * 17 | 
ソースコード
def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    idx += 1
    k = int(data[idx])
    idx += 1
    A = list(map(int, data[idx:idx+N]))
    idx += N
    B = list(map(int, data[idx:idx+N]))
    
    if sorted(A) != sorted(B):
        print("No")
        return
    
    if A == B:
        print("Yes")
        return
    
    if k <= 2:
        print("Yes")
        return
    
    if k % 2 == 0:
        print("Yes")
        return
    
    # Compute the permutation's parity
    pos_in_B = {num: idx for idx, num in enumerate(B)}
    visited = [False] * N
    parity = 0
    
    for i in range(N):
        if not visited[i]:
            cycle_length = 0
            j = i
            while not visited[j]:
                visited[j] = True
                j = pos_in_B[A[j]]
                cycle_length += 1
            parity += (cycle_length - 1)
    
    if parity % 2 == 0:
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()
            
            
            
        
            
gew1fw