結果

問題 No.482 あなたの名は
ユーザー Dugong
提出日時 2017-03-16 21:08:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 467 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 34,804 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-04 02:43:40
合計ジャッジ時間 2,311 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%d %d",&n,&k);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf("%d",&d);
      |                 ~~~~~^~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<algorithm>
using namespace std;

int a[200000];
bool used[200000];

int dfs(int x,int cnt){
	if(used[a[x]]||x==a[x]) return cnt;
	else{
		used[x] = true;
		return dfs(a[x],cnt+1);
	}
}

int main(){
	int n,k,m = 0;
	scanf("%d %d",&n,&k);
	fill(used,used+n,false);
	for(int i=0;i<n;i++){
		int d;
		scanf("%d",&d);
		a[d-1] = i;
	}
	for(int i=0;i<n;i++) m += dfs(i,0);
	if(m<=k&&(m-k)%2==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}
0