提出 #12550661


ソースコード 拡げる

# Studying https://img.atcoder.jp/abc164/editorial.pdf

# Inputs

N,M,S = gets.split.map(&:to_i)
E = Array.new(N){ [] }
M.times{
	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{
	c,d = gets.split.map(&:to_i)
	lambda{|_, ̄|
		x = ( ̄-_+c-1)/c
		return c*x, d*x
	}
}

# Tools

class PQ
	def initialize
		@h = [] # min-heap
	end

	def enq v
		@h << v
		up_heap
	end

	def deq
		min, last = @h[0], @h.pop
		unless @h.empty?
			@h[0] = last
			dn_heap
		end
		return min
	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,2450].min<<6 | u
}
Я = lambda{|r|
	next r>>18, r>>6&4095, r&63
}

# Main

n,T = 0, [nil]*N
2,3,4 = [-1]*N, [0]*N, [nil]*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

	least_s = 2450
	E[u].each{|v,a,b|
		z, y = 2[v]+a, 3[v]+a # z < y
		if z < s
			c, d = s < y ? X[v][s-a,3[v]] : [0,0]
			if 4[v] != r = R[t+b+d,s-a+c,v]
				Q.enq(4[v] = r)
			end
		end
		least_s = [[s,z].max+1,least_s].min
	}
	3[u] = least_s

	c,d = X[u][s,least_s]
	if 4[u] != r = R[t+d,s+c,u]
		Q.enq(4[u] = r)
	end
end

# Output

T.shift
p(*T)

提出情報

提出日時
問題 E - Two Currencies
ユーザ ds14050
言語 Ruby (2.7.1)
得点 500
コード長 1733 Byte
結果 AC
実行時間 154 ms
メモリ 14520 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 5
AC × 27
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
line_1.txt AC 53 ms 14456 KiB
line_2.txt AC 154 ms 14348 KiB
random_01.txt AC 59 ms 14484 KiB
random_02.txt AC 60 ms 14260 KiB
random_03.txt AC 55 ms 14144 KiB
random_04.txt AC 61 ms 14292 KiB
random_05.txt AC 66 ms 14512 KiB
random_06.txt AC 55 ms 14388 KiB
random_07.txt AC 53 ms 14520 KiB
random_08.txt AC 60 ms 14192 KiB
random_09.txt AC 54 ms 14312 KiB
random_10.txt AC 65 ms 14404 KiB
random_11.txt AC 56 ms 14304 KiB
random_12.txt AC 54 ms 14316 KiB
random_13.txt AC 63 ms 14384 KiB
random_14.txt AC 54 ms 14164 KiB
random_15.txt AC 58 ms 14340 KiB
random_16.txt AC 57 ms 14184 KiB
random_17.txt AC 67 ms 14200 KiB
random_18.txt AC 54 ms 14300 KiB
random_19.txt AC 56 ms 14372 KiB
random_20.txt AC 53 ms 14132 KiB
sample_01.txt AC 54 ms 14352 KiB
sample_02.txt AC 51 ms 14140 KiB
sample_03.txt AC 54 ms 14244 KiB
sample_04.txt AC 51 ms 14172 KiB
sample_05.txt AC 52 ms 14352 KiB