結果

問題 No.482 あなたの名は
ユーザー suppy193suppy193
提出日時 2017-02-13 13:35:14
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 29,288 KB
最終ジャッジ日時 2023-08-28 15:34:17
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,256 KB
testcase_01 AC 75 ms
15,176 KB
testcase_02 AC 78 ms
15,104 KB
testcase_03 AC 76 ms
15,364 KB
testcase_04 AC 77 ms
15,064 KB
testcase_05 AC 76 ms
15,364 KB
testcase_06 AC 76 ms
15,332 KB
testcase_07 AC 76 ms
15,204 KB
testcase_08 AC 77 ms
15,140 KB
testcase_09 AC 76 ms
15,252 KB
testcase_10 AC 77 ms
15,180 KB
testcase_11 AC 76 ms
15,068 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 168 ms
29,124 KB
testcase_17 AC 167 ms
29,288 KB
testcase_18 AC 168 ms
29,024 KB
testcase_19 WA -
testcase_20 AC 169 ms
29,124 KB
testcase_21 AC 167 ms
29,064 KB
testcase_22 WA -
testcase_23 AC 168 ms
29,032 KB
testcase_24 WA -
testcase_25 AC 168 ms
29,232 KB
testcase_26 WA -
testcase_27 AC 168 ms
29,148 KB
testcase_28 AC 169 ms
29,288 KB
testcase_29 AC 168 ms
28,980 KB
testcase_30 AC 76 ms
15,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, k = gets.strip.split(' ').map(&:to_i)
d = gets.strip.split(' ').map(&:to_i)
count = 0
count2 = 0
(0...n).each do |i|
	next if d[i] - 1 == i
	# print "#{i}:d[i]=#{d[i]} d[d[i] - 1]=#{d[d[i] - 1]}"
	if d[d[i] - 1] == i + 1
		count += 1 
	else
		count2 += 1
	end
end

# p count
# p count2
if count2 == 0
	if k - count / 2 >= 0 && (k - count / 2) % 2 == 0
		puts "YES"
	else
		puts "NO"
	end
elsif k - count / 2 - count2 + 1 >= 0 && (k - count / 2 - count2 + 1) % 2 == 0
	puts "YES"
else
	puts "NO"
end
0