結果

問題 No.100 直列あみだくじ
ユーザー GOTKAKO
提出日時 2025-07-02 01:27:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 580 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 198,284 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-07-02 01:27:49
合計ジャッジ時間 3,499 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<int> A(N);
    for(auto &a : A) cin >> a,a--;

    vector<bool> already(N);
    vector<int> len(N+1);
    for(int i=0; i<N; i++){
        if(already.at(i)) continue;
        already.at(i) = true;
        int loop = 1,pos = A.at(i);
        while(pos != i) already.at(pos) = true,loop++,pos = A.at(pos);
        if(loop%2 == 0) len.at(loop)++;
    }
    for(auto l : len) if(l%2){cout << "No\n"; return 0;}
    cout << "Yes\n";
}
0