Submission #50168931


Source Code Expand

class BIT
	def initialize n
		@n = n
		@a = [0]*(n+1)
	end

	def [] i
		i += 1
		s = 0
		while 0<i
			s += @a[i]
			i &= i-1
		end
		return s
	end

	def add i,d
		i += 1
		while i<=@n
			@a[i] += d
			i += i&-i
		end
	end
end

(N,M),A,B = $<.map{|ln| ln.split.map(&:to_i) }

S = BIT.new N+1
S.add 0,A[0]
A.each_cons(2).with_index(1){|(a0,a1),i|
	S.add i,a1-a0
}
B.each{|b|
	s = S[b]
	next if s<1

	# 取り出し
	S.add b,-s
	S.add b+1,s

	# N-1 まで1ずつ配る
	c = [b+s,N-1].min
	S.add b+1,1
	S.add c+1,-1
	s -= c-b
	next if s<1

	# 0 から N-1 まで均等に配る
	if N<=s
		c,s = s.divmod N
		S.add 0,c
	end
	next if s<1

	# 0 から1ずつ配る
	S.add 0,1
	S.add s,-1
}

puts N.times.map{|i| S[i] }*' '

Submission Info

Submission Time
Task E - Mancala 2
User ds14050
Language Ruby (ruby 3.2.2)
Score 475
Code Size 780 Byte
Status AC
Exec Time 572 ms
Memory 56044 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 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, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 195 ms 33928 KiB
random_02.txt AC 255 ms 35228 KiB
random_03.txt AC 177 ms 28444 KiB
random_04.txt AC 49 ms 17428 KiB
random_05.txt AC 244 ms 35196 KiB
random_06.txt AC 256 ms 35108 KiB
random_07.txt AC 150 ms 28436 KiB
random_08.txt AC 117 ms 22992 KiB
random_09.txt AC 256 ms 35172 KiB
random_10.txt AC 248 ms 35192 KiB
random_11.txt AC 171 ms 27412 KiB
random_12.txt AC 68 ms 18864 KiB
random_13.txt AC 568 ms 55604 KiB
random_14.txt AC 456 ms 46516 KiB
random_15.txt AC 348 ms 44088 KiB
random_16.txt AC 291 ms 32560 KiB
random_17.txt AC 572 ms 55980 KiB
random_18.txt AC 516 ms 42108 KiB
random_19.txt AC 379 ms 43728 KiB
random_20.txt AC 481 ms 48396 KiB
random_21.txt AC 571 ms 55504 KiB
random_22.txt AC 531 ms 53924 KiB
random_23.txt AC 418 ms 44148 KiB
random_24.txt AC 437 ms 42976 KiB
random_25.txt AC 44 ms 17020 KiB
random_26.txt AC 44 ms 17136 KiB
random_27.txt AC 566 ms 56044 KiB
random_28.txt AC 368 ms 36780 KiB
random_29.txt AC 477 ms 47356 KiB
random_30.txt AC 269 ms 35280 KiB
random_31.txt AC 276 ms 33972 KiB
random_32.txt AC 270 ms 35168 KiB
sample_01.txt AC 43 ms 17140 KiB
sample_02.txt AC 44 ms 17120 KiB
sample_03.txt AC 44 ms 17252 KiB