Submission #43667957


Source Code Expand

N = gets.to_i
B = gets.chomp

O = [o = -1]
O<<o while o = B.index(?0,o+1)
O<<j = N
*S = 0
O.reverse_each{|i|
	ones = j-i-1
	# f(,i)=1 として f(,k) (i<=k<j) の和
	S<<1+ones/2+S[-1] # それの累積和
	j = i
}
S.reverse!

p B.each_byte.with_index.sum{|b,i|
	(O.shift; S.shift) while O[0]<=i
	next_o = O[0]
	after_next_o = S[0]
	ones = next_o-i-1
	if 0<b&1
		1+ones/2+after_next_o
	else
		(ones+1)/2+after_next_o
	end
}

Submission Info

Submission Time
Task E - NAND repeatedly
User ds14050
Language Ruby (2.7.1)
Score 450
Code Size 450 Byte
Status AC
Exec Time 528 ms
Memory 39244 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 32
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt, 02_handmade_15.txt, 02_handmade_16.txt, 02_handmade_17.txt, 02_handmade_18.txt, 02_handmade_19.txt, 02_handmade_20.txt, 02_handmade_21.txt, 02_handmade_22.txt, 02_handmade_23.txt, 02_handmade_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt, 02_handmade_29.txt, 02_handmade_30.txt, 02_handmade_31.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 62 ms 13980 KiB
00_sample_01.txt AC 59 ms 14240 KiB
01_random_02.txt AC 395 ms 26644 KiB
01_random_03.txt AC 392 ms 26444 KiB
01_random_04.txt AC 394 ms 26608 KiB
01_random_05.txt AC 396 ms 26548 KiB
01_random_06.txt AC 397 ms 26612 KiB
01_random_07.txt AC 347 ms 22956 KiB
01_random_08.txt AC 304 ms 22792 KiB
01_random_09.txt AC 299 ms 22660 KiB
01_random_10.txt AC 285 ms 22548 KiB
01_random_11.txt AC 141 ms 17044 KiB
02_handmade_12.txt AC 371 ms 30912 KiB
02_handmade_13.txt AC 190 ms 15992 KiB
02_handmade_14.txt AC 526 ms 39244 KiB
02_handmade_15.txt AC 251 ms 16180 KiB
02_handmade_16.txt AC 528 ms 38980 KiB
02_handmade_17.txt AC 252 ms 16204 KiB
02_handmade_18.txt AC 60 ms 14076 KiB
02_handmade_19.txt AC 60 ms 14268 KiB
02_handmade_20.txt AC 60 ms 14040 KiB
02_handmade_21.txt AC 60 ms 14132 KiB
02_handmade_22.txt AC 59 ms 14168 KiB
02_handmade_23.txt AC 62 ms 14420 KiB
02_handmade_24.txt AC 60 ms 14184 KiB
02_handmade_25.txt AC 59 ms 14236 KiB
02_handmade_26.txt AC 59 ms 14160 KiB
02_handmade_27.txt AC 64 ms 14196 KiB
02_handmade_28.txt AC 60 ms 14252 KiB
02_handmade_29.txt AC 58 ms 14100 KiB
02_handmade_30.txt AC 60 ms 14244 KiB
02_handmade_31.txt AC 60 ms 14204 KiB