結果

問題 No.482 あなたの名は
ユーザー Konton7
提出日時 2019-05-25 01:36:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,676 KB
最終ジャッジ日時 2024-09-17 15:01:01
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = [ int(v) for v in input().split() ]

number_list = [ (int(v)-1) for v in input().split() ]
change_list= []


for i in range(n):
	if number_list[i] == i:
		 number_list[i] = -1
	elif number_list[i] == -1:
		 pass
	else:
		temp_list = [number_list[i]]
		
		next_i = number_list[i]
		number_list[i] = -1
		while next_i not in [i,-1] :
			temp_list.append(number_list[next_i])
			now_i = next_i
			next_i = number_list[next_i]
			number_list[now_i] = -1
		change_list.append(temp_list)


change_list = [len(change_list[i])-1 for i in range(len(change_list))]


if k >= sum(change_list) and (k - sum(change_list)) % 2 == 0:
	print("YES")
else:
	print("NO")
0