結果

問題 No.1623 三角形の制作
ユーザー 小野寺健小野寺健
提出日時 2021-11-01 21:21:14
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 703 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 40,320 KB
最終ジャッジ日時 2024-04-18 20:28:34
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def binary_search(a, n, k, lower)
	left = 0
	right = n
	while left < right do
		mid = (left + right) / 2
		if lower ? a[mid] < k : a[mid] <= k then
			left = mid + 1
		else
			right = mid
		end
	end
	return right
end

n = gets.to_i
r = gets.split(" ").map{|s| s.to_i}.sort
g = gets.split(" ").map{|s| s.to_i}.sort
b = gets.split(" ").map{|s| s.to_i}.sort

cnt = 0
i = 0
while i < n do
	a = r[i]
	j = binary_search(r, n, a, false)
	an = j - i
	k = binary_search(g, n, a, false)
	l = 0
	while l < k do
		m = binary_search(g, n, g[l], false)
		bn = m - l
		o = binary_search(b, n, a, false)
		p = binary_search(b, n, a - g[l] + 1, true)
		cn = o - p
		cnt += an * bn * cn
		l = m
	end
	i = j
end

puts cnt	
0