結果
| 問題 | 
                            No.2089 置換の符号
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-03-20 18:43:48 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 47 ms / 2,000 ms | 
| コード長 | 434 bytes | 
| コンパイル時間 | 276 ms | 
| コンパイル使用メモリ | 82,824 KB | 
| 実行使用メモリ | 62,744 KB | 
| 最終ジャッジ日時 | 2025-03-20 18:43:52 | 
| 合計ジャッジ時間 | 2,370 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
n = int(input())
permutation = list(map(int, input().split()))
visited = [False] * n
count = 0
for i in range(1, n + 1):
    if not visited[i - 1]:
        current = i
        cycle_length = 0
        while not visited[current - 1]:
            visited[current - 1] = True
            current = permutation[current - 1]
            cycle_length += 1
        count += (cycle_length - 1)
sign = 1 if count % 2 == 0 else -1
print(sign)
            
            
            
        
            
lam6er