Submission #51606089


Source Code Expand

N = gets.to_i
S = gets.chomp.bytes
Sz = S.size
Z = N*Sz
T = gets.chomp.bytes

I = Array.new(123){[]}
S.each_with_index{|ab,i|
	I[ab]<<i
}
NxJ = I.map{|is|
	next if is.empty?
	nx = [nil]*Sz
	i0 = -1
	is.each_with_index{|i,j|
		nx.fill j,i0+1..i0=i
	}
	nx.fill 0,i0+1...Sz
}
NxN = lambda{|ab,i,n|
	next i-1 if n<1
	is = I[ab]
	next Z if is.empty?
	is_j = NxJ[ab][i%Sz] # 位置 i を含む
	j = is_j ? i/Sz*Sz+is[is_j] : i+Sz+is[0]
	is_j ||= 0
	n -= 1 # j が 1st of n
	# 1 cycle S.size 文字で ab は is.size 回現れる
	c,n = n.divmod is.size
	j += c*Sz
	if 0<n
		is_k = (is_j+n)%is.size
		j += is[is_k]-is[is_j]
		j += Sz if is_k<=is_j
	end
#p [ab.chr,i,j,j<Z]
	next j
}

p (0..).bsearch{|k|
	i = 0
#warn k
	T.any?{|ab|
		Z<i = NxN[ab,i,k]+1
	}
}-1

Submission Info

Submission Time
Task F - SSttrriinngg in StringString
User ds14050
Language Ruby (ruby 3.2.2)
Score 0
Code Size 800 Byte
Status WA
Exec Time 2180 ms
Memory 41076 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 525
Status
AC × 3
AC × 42
WA × 8
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_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, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_zero_00.txt, 03_zero_01.txt, 03_zero_02.txt, 03_zero_03.txt, 03_zero_04.txt, 03_zero_05.txt, 04_border_00.txt, 04_border_01.txt, 04_border_02.txt, 04_border_03.txt, 05_handmade_00.txt, 05_handmade_01.txt, 05_handmade_02.txt, 05_handmade_03.txt, 05_handmade_04.txt, 05_handmade_05.txt, 05_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 46 ms 17336 KiB
00_sample_01.txt AC 45 ms 17220 KiB
00_sample_02.txt AC 46 ms 17536 KiB
01_random_00.txt AC 1652 ms 21384 KiB
01_random_01.txt AC 1768 ms 22412 KiB
01_random_02.txt WA 2028 ms 24724 KiB
01_random_03.txt WA 2172 ms 28272 KiB
01_random_04.txt WA 2180 ms 41076 KiB
01_random_05.txt AC 224 ms 20208 KiB
01_random_06.txt AC 264 ms 21728 KiB
01_random_07.txt AC 276 ms 23912 KiB
01_random_08.txt WA 294 ms 27452 KiB
01_random_09.txt AC 310 ms 40204 KiB
01_random_10.txt AC 83 ms 20332 KiB
01_random_11.txt AC 89 ms 21784 KiB
01_random_12.txt AC 93 ms 23732 KiB
01_random_13.txt AC 96 ms 27468 KiB
01_random_14.txt AC 106 ms 40148 KiB
01_random_15.txt AC 67 ms 20236 KiB
01_random_16.txt AC 69 ms 21044 KiB
01_random_17.txt AC 71 ms 23860 KiB
01_random_18.txt AC 74 ms 27576 KiB
01_random_19.txt AC 85 ms 40268 KiB
01_random_20.txt AC 66 ms 20500 KiB
01_random_21.txt AC 67 ms 20880 KiB
01_random_22.txt AC 69 ms 23732 KiB
01_random_23.txt AC 72 ms 27364 KiB
01_random_24.txt AC 81 ms 39980 KiB
02_random2_00.txt AC 1498 ms 20208 KiB
02_random2_01.txt AC 663 ms 18700 KiB
02_random2_02.txt AC 103 ms 21920 KiB
02_random2_03.txt WA 1470 ms 25336 KiB
02_random2_04.txt WA 694 ms 34288 KiB
03_zero_00.txt AC 74 ms 19484 KiB
03_zero_01.txt AC 52 ms 18080 KiB
03_zero_02.txt AC 73 ms 22632 KiB
03_zero_03.txt WA 78 ms 27300 KiB
03_zero_04.txt WA 75 ms 32748 KiB
03_zero_05.txt AC 54 ms 18384 KiB
04_border_00.txt AC 65 ms 19288 KiB
04_border_01.txt AC 50 ms 17732 KiB
04_border_02.txt AC 54 ms 18676 KiB
04_border_03.txt AC 56 ms 18440 KiB
05_handmade_00.txt AC 73 ms 21028 KiB
05_handmade_01.txt AC 1636 ms 21516 KiB
05_handmade_02.txt AC 46 ms 17448 KiB
05_handmade_03.txt AC 65 ms 20444 KiB
05_handmade_04.txt AC 45 ms 17308 KiB
05_handmade_05.txt AC 45 ms 17260 KiB
05_handmade_06.txt AC 45 ms 17272 KiB