結果

問題 No.100 直列あみだくじ
ユーザー koyumeishi
提出日時 2014-12-12 00:50:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 817 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 76,460 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 01:35:24
合計ジャッジ時間 1,905 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <ctime>

using namespace std;


int main(){
	srand((unsigned)time(NULL));
	
	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);
	vector<int> loop(n+1, 0);
	
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		used[i] = true;
		
		int pos = a[i];
		int cnt = 1;
		while(!used[pos]){
			used[pos] = true;
			pos = a[pos];
			cnt++;
		}
		loop[cnt] = (loop[cnt]+1)%2;
	}

	bool valid = true;
	for(int i=0; i<n+1; i++){
		if(i%2==1) continue;
		if(loop[i]%2!=0) valid = false;
	}

	cout << (valid?"Yes":"No") << endl;
	return 0;
}
0