結果

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

ソースコード

diff #

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

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

int dfs(int x,int cnt){
	used[x] = true;
	if(used[a[x]]||x==a[x]) return cnt;
	else 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[i] = d - 1;
	}
	for(int i=0;i<n;i++) m += dfs(i,0);
	if(m<=k&&(k-m)%2==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}
0