結果
問題 | No.2089 置換の符号 |
ユーザー |
![]() |
提出日時 | 2022-09-30 21:26:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 528 bytes |
コンパイル時間 | 1,699 ms |
コンパイル使用メモリ | 170,492 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-22 22:16:56 |
合計ジャッジ時間 | 2,756 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++){cin >> A[i];A[i]--;}vector<bool> used(N, false);int cnt = 0;for (int i = 0; i < N; i++){if (!used[i]){used[i] = true;int j = i;while (true){j = A[j];if (used[j]){break;}used[j] = true;}cnt++;}}if (cnt % 2 == N % 2){cout << 1 << endl;} else {cout << -1 << endl;}}