結果

問題 No.100 直列あみだくじ
ユーザー kotatsugame
提出日時 2021-01-10 06:53:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 375 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 65,492 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-20 10:03:10
合計ジャッジ時間 2,183 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N,P[50];
bool vis[50];
int cnt[50];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		P[i]--;
	}
	int outc=0;
	for(int i=0;i<N;i++)if(!vis[i])
	{
		int u=i;
		int c=0;
		do{
			vis[u]=true;
			u=P[u];
			c++;
		}while(u!=i);
		if(c%2==0)
		{
			if(cnt[c]^=1)outc++;
			else outc--;
		}
	}
	cout<<(outc?"No":"Yes")<<endl;
}
0