結果

問題 No.482 あなたの名は
ユーザー fiord
提出日時 2017-02-27 08:05:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 168,012 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-11 19:01:11
合計ジャッジ時間 3,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,k;	cin>>n>>k;
	int diff=0,same=0;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==i+1)	same++;
		else 	diff++;
	}
	k-=max(diff-1,0);
	if(k<0)	cout<<"NO"<<endl;
	else if(k%2==0)	cout<<"YES"<<endl;
	else{
		int next=0;
		for(int i=0;i<n;i++){
			if(a[i]!=i+1){
				next=i+1;
				break;
			}
		}
		if(next==0)	cout<<"NO"<<endl;
		else{
			while(a[next-1]!=0){
				diff--;
				int tmp=next;
				next=a[next-1];	a[tmp-1]=0;
			}
			if(diff>0)	cout<<"YES"<<endl;
			else 	cout<<"NO"<<endl;
		}
	}
	return 0;
}
0