結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
19,628 KB
testcase_01 AC 76 ms
15,200 KB
testcase_02 AC 75 ms
15,328 KB
testcase_03 AC 76 ms
15,160 KB
testcase_04 AC 75 ms
15,184 KB
testcase_05 AC 75 ms
15,168 KB
testcase_06 AC 75 ms
15,280 KB
testcase_07 AC 89 ms
15,292 KB
testcase_08 AC 82 ms
15,276 KB
testcase_09 AC 76 ms
15,252 KB
testcase_10 AC 81 ms
15,152 KB
testcase_11 AC 85 ms
15,156 KB
testcase_12 AC 90 ms
15,304 KB
testcase_13 AC 81 ms
15,304 KB
testcase_14 AC 80 ms
15,152 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, k = gets.strip.split(' ').map(&:to_i)
d = gets.strip.split(' ').map(&:to_i)
=begin
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
=end

count = 0
(0...n - 1).each do |i|
	next if d[i] - 1 == i
	jmin = 0
	min = Float::INFINITY
	(i + 1...n).each do |j|
		if min > d[j]
			min = d[j]
			jmin = j
		end
	end
	d[i], d[jmin] = d[jmin], d[i]
	count += 1
end
# p count
if k - count >= 0 && (k - count) % 2 == 0
	puts "YES"
else
	puts "NO"
end
0