結果
| 問題 | No.33 アメーバがたくさん |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-02 21:58:44 |
| 言語 | Crystal (1.14.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,290 bytes |
| 記録 | |
| コンパイル時間 | 925 ms |
| コンパイル使用メモリ | 178,612 KB |
| 最終ジャッジ日時 | 2024-11-14 19:24:11 |
| 合計ジャッジ時間 | 1,288 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[2mShowing last frame. Use --error-trace for full trace.[0m
In [4mMain.cr:52:47[0m
[2m 52 | [0m[1midx=(0...self.size).bsearch{|i|yield self[i]}[0m
[32;1m^[0m
[33;1mError: expected argument #1 to 'Array(Tuple(Int32, Int32, Int32))#[]' to be Int, not (Float64 | Int32)[0m
Overloads are:
- Array(T)#[](start : Int, count : Int)
- Array(T)#[](range : Range)
- Indexable(T)#[](index : Int)
ソースコード
#!/usr/bin/env crystal
struct Range(B, E)
#Perform binary search
#Based on Marc-André Lafortune's Ruby backports implementation, ported by @cielavenir
def bsearch
#return to_enum(:bsearch) unless block_given?
from = self.begin
to = self.end
unless from.is_a?(Int) && to.is_a?(Int)
# Float support is currently dropped
raise "can't do binary search for #{from.class}"
end
midpoint = 0 # placeholder
#convert = ->{ (pointerof(midpoint) as Pointer(Int64)).value }
convert = ->{ midpoint }
to -= 1 if excludes_end?
satisfied = nil
while from <= to
midpoint = (from + to)/2
result = yield(cur = convert.call)
case result
when Int
return cur if result == 0
result = result < 0
when Float
return cur if result == 0
result = result < 0
when true
satisfied = cur
when nil, false
# nothing to do
else
raise "wrong argument type #{result.class} (must be numeric, true, false or nil)"
end
if result
to = midpoint - 1
else
from = midpoint + 1
end
end
satisfied
end
end
class Array(T)
def bsearch
idx=(0...self.size).bsearch{|i|yield self[i]}
idx ? self[idx] : nil
end
def bsearch_index
(0...self.size).bsearch{|i|yield self[i]}
end
end
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
dic={} of Int64 => Array(Tuple(Int64,Int64))
n,d,t=gets.not_nil!.split.map(&.to_i64)
gets.not_nil!.split.map(&.to_i64).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