結果

問題 No.100 直列あみだくじ
ユーザー face4
提出日時 2019-12-07 20:59:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 08:12:02
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

// editorialを読んだ
#include<iostream>
#include<vector>
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]--;
    int evenLoop = 0;
    vector<bool> vis(n, 0);
    for(int i = 0; i < n; i++){
        if(vis[i])  continue;
        int len = 0;
        int now = i;
        while(!vis[i]){
            vis[i] = true;
            len++;
            i = a[i];
        }
        if(len%2 == 0)  evenLoop++;
    }
    cout << (evenLoop%2 == 0 ? "Yes" : "No") << endl;
    return 0;
}
0