Submission #12498094
Source Code Expand
# Studying https://img.atcoder.jp/abc164/editorial.pdf
# Inputs
N,M,S = gets.split.map(&:to_i)
E = Array.new(N){ [] }
M.times.map{
u,v,a,b = gets.split.map(&:to_i)
E[u-1] << [v-1,a,b]
E[v-1] << [u-1,a,b]
}
X = N.times.map{ gets.split.map(&:to_i) }
# Tools
class PQ
def initialize
@h = [] # min-heap
end
def enq(v)
@h.push(v)
up_heap
end
def deq
max, last = @h[0], @h.pop
unless @h.empty?
@h[0] = last
dn_heap
end
return max
end
private
def up_heap
i, up = @h.size-1, @h[-1]
while 0 <= (iP = (i-1)/2)
break unless up < @h[iP]
@h[i], i = @h[iP], iP
end
@h[i] = up
end
def dn_heap
i, dn, size = 0, @h[0], @h.size
while (iC = 2*i+1) < size
iC += 1 if iC+1 < size and @h[iC+1] < @h[iC]
break unless @h[iC] < dn
@h[i], i = @h[iC], iC
end
@h[i] = dn
end
end
R = lambda{|t,s,u|
next t<<18 | [s,4095].min<<6 | u
}
Я = lambda{|r|
next r>>18, r>>6&4095, r&63
}
# Main
n,T,2 = 0, [nil]*N, [-1]*N
Q = PQ.new; Q.enq R[0,S,0]
while r = Q.deq
t,s,u = Я[r]
next if s <= 2[u] # 銭なしの再訪に用なし
2[u] = s
unless T[u] # first arrived.
n, T[u] = n+1, t
break if n == N # completed.
end
E[u].each{|v,a,b|
Q.enq R[t+b,s-a,v] if 2[v] < s-a
}
c,d = X[u]
Q.enq R[t+d,s+c,u]
end
# Output
T.shift
p(*T)
__END__
こういう入力に弱い。
9 8 0
1 2 50 1
2 3 50 1
3 4 50 1
4 5 50 1
5 6 50 1
6 7 50 1
7 8 50 1
8 9 50 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
Submission Info
| Submission Time |
|
| Task |
E - Two Currencies |
| User |
ds14050 |
| Language |
Ruby (2.7.1) |
| Score |
500 |
| Code Size |
1565 Byte |
| Status |
AC |
| Exec Time |
205 ms |
| Memory |
14528 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| All |
line_1.txt, line_2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt |
| Case Name |
Status |
Exec Time |
Memory |
| line_1.txt |
AC |
53 ms |
14396 KiB |
| line_2.txt |
AC |
205 ms |
14332 KiB |
| random_01.txt |
AC |
55 ms |
14432 KiB |
| random_02.txt |
AC |
65 ms |
14472 KiB |
| random_03.txt |
AC |
54 ms |
14256 KiB |
| random_04.txt |
AC |
58 ms |
14468 KiB |
| random_05.txt |
AC |
68 ms |
14524 KiB |
| random_06.txt |
AC |
54 ms |
14320 KiB |
| random_07.txt |
AC |
52 ms |
14512 KiB |
| random_08.txt |
AC |
60 ms |
14512 KiB |
| random_09.txt |
AC |
54 ms |
14360 KiB |
| random_10.txt |
AC |
75 ms |
14376 KiB |
| random_11.txt |
AC |
56 ms |
14348 KiB |
| random_12.txt |
AC |
55 ms |
14284 KiB |
| random_13.txt |
AC |
63 ms |
14528 KiB |
| random_14.txt |
AC |
53 ms |
14316 KiB |
| random_15.txt |
AC |
58 ms |
14296 KiB |
| random_16.txt |
AC |
61 ms |
14284 KiB |
| random_17.txt |
AC |
74 ms |
14508 KiB |
| random_18.txt |
AC |
52 ms |
14352 KiB |
| random_19.txt |
AC |
55 ms |
14312 KiB |
| random_20.txt |
AC |
54 ms |
14488 KiB |
| sample_01.txt |
AC |
53 ms |
14360 KiB |
| sample_02.txt |
AC |
53 ms |
14316 KiB |
| sample_03.txt |
AC |
53 ms |
14328 KiB |
| sample_04.txt |
AC |
51 ms |
14144 KiB |
| sample_05.txt |
AC |
51 ms |
14388 KiB |