結果

問題 No.33 アメーバがたくさん
ユーザー cielciel
提出日時 2020-08-14 01:54:36
言語 Crystal
(1.11.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,010 bytes
コンパイル時間 20,109 ms
コンパイル使用メモリ 257,560 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-13 11:47:03
合計ジャッジ時間 17,736 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def checkio(data)
	result=0
	se=[] of Tuple(Int64,Int64)
	data.each{|e|
		l,r=e
		right_idx=(0...se.size).bsearch{|i|
			x={l,0}<=>se[i]
			x<=0
		}||se.size #l <= se[right][0]
		if right_idx>0
			left_idx=right_idx-1
			if l<=se[left_idx][1]+1 # overlap with left
				l=se[left_idx][0]
				r=[r,se[left_idx][1]].max
				result-=se[left_idx][1]-se[left_idx][0]+1
				se.delete_at(left_idx)
				right_idx-=1
			end
		end
		while right_idx<se.size && se[right_idx][0]<=r # overlap with right
			r=[r,se[right_idx][1]].max
			result-=se[right_idx][1]-se[right_idx][0]+1
			se.delete_at(right_idx)
		end
		result+=r-l+1
		se.insert(right_idx,{l,r})
	}
	return result
end

lib C;fun strtoll(s: UInt8*,p: UInt8*,b: Int32): Int64;end
dic={} of Int64 => Array(Tuple(Int64,Int64))
n,d,t=gets.not_nil!.split.map{|e|C.strtoll(e,nil,10)}
gets.not_nil!.split.map{|e|C.strtoll(e,nil,10)}.each{|e|
	mod=e%d
	dic[mod]||=[] of Tuple(Int64,Int64)
	dic[mod]<<{(e-mod)//d-t,(e-mod)//d+t}
}
r=0_i64
dic.each{|k,v|r+=checkio(v)}
p r
0