Submission #50640033


Source Code Expand

Copy
class LastNSum
def initialize n
@n = n
@sum =
@first =
@last = 0
@values = [0]*n
end
attr_reader :sum
def << value
if @first == @last
@sum -= @values[@first]
@first = (@first+1)%@n
end
@sum += @values[@last] = value
@last = (@last+1)%@n
end
end
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class LastNSum
	def initialize n
		@n = n
		@sum =
		@first =
		@last = 0
		@values = [0]*n
	end

	attr_reader :sum

	def << value
		if @first == @last
			@sum -= @values[@first]
			@first = (@first+1)%@n
		end
		@sum += @values[@last] = value
		@last = (@last+1)%@n
	end
end

N,L,D = gets.split.map(&:to_i)

*P = 1.0
s = LastNSum.new D
s<<P[-1]
1.upto(N){|y|
	P<<s.sum/D
	s<<(y<L ? P[-1] : 0)
}

勝つ = nil
振って勝つ = LastNSum.new D
振らずに勝つ = 1.0
N.downto(0){|y|
	振らずに勝つ -= P[y] if L<=y
	勝つ = [振らずに勝つ,振って勝つ.sum/D].max
	振って勝つ<<勝つ
}

p 勝つ

Submission Info

Submission Time
Task F - Black Jack
User ds14050
Language Ruby (ruby 3.2.2)
Score 550
Code Size 655 Byte
Status AC
Exec Time 84 ms
Memory 22744 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 2
AC × 22
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 46 ms 17228 KB
00_sample_02.txt AC 82 ms 22524 KB
01_test_01.txt AC 79 ms 19596 KB
01_test_02.txt AC 81 ms 19504 KB
01_test_03.txt AC 66 ms 20232 KB
01_test_04.txt AC 45 ms 17244 KB
01_test_05.txt AC 57 ms 18176 KB
01_test_06.txt AC 79 ms 20664 KB
01_test_07.txt AC 69 ms 18724 KB
01_test_08.txt AC 56 ms 18424 KB
01_test_09.txt AC 75 ms 19548 KB
01_test_10.txt AC 64 ms 19600 KB
01_test_11.txt AC 80 ms 21040 KB
01_test_12.txt AC 80 ms 20332 KB
01_test_13.txt AC 80 ms 19592 KB
01_test_14.txt AC 81 ms 22504 KB
01_test_15.txt AC 81 ms 20468 KB
01_test_16.txt AC 84 ms 22744 KB
01_test_17.txt AC 78 ms 22612 KB
01_test_18.txt AC 80 ms 22720 KB
01_test_19.txt AC 81 ms 22692 KB
01_test_20.txt AC 79 ms 22560 KB


2025-04-15 (Tue)
03:34:08 +00:00