結果

問題 No.1006 Share an Integer
ユーザー 小野寺健小野寺健
提出日時 2021-11-06 17:53:45
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 406 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 33,956 KB
最終ジャッジ日時 2024-04-25 06:26:55
合計ジャッジ時間 7,221 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
19,236 KB
testcase_01 AC 94 ms
12,160 KB
testcase_02 AC 89 ms
12,160 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 91 ms
12,288 KB
testcase_05 AC 90 ms
12,160 KB
testcase_06 AC 87 ms
12,288 KB
testcase_07 AC 90 ms
12,288 KB
testcase_08 AC 91 ms
12,160 KB
testcase_09 AC 91 ms
12,032 KB
testcase_10 AC 88 ms
12,160 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

X = gets.to_i

d = Array.new(X+1, 2)
d[0] = 0
d[1] = 1
2.upto(X) {|i|
	(2*i).step(X, i) {|j|
		d[j] += 1
	}
}

min = X
minpair = nil

1.upto(X/2) {|a|
	b = X - a
	v = (a - d[a] - b + d[b]).abs
	if min > v then
		min = v
		minpair = a == b ? [[a, b]] : [[a, b], [b, a]]
	elsif min == v then
		minpair << [a, b]
		minpair << [b, a] if a != b
	end
}

minpair.sort_by{|x| x[0]}.each {|a, b|
	puts "#{a} #{b}"
}
0