Submission #6996142


Source Code Expand

Copy
s = input()
t = input()

a = [[] for i in range(26)]

for i in range(len(s)):
	a[ord(s[i]) - ord('a')].append(i)

cnt = 1

prev = -1
i = 0 
while(i < len(t)):
	l = t[i]
	indi = ord(l) - ord('a')
	li = a[indi]

	if(li == []):
		print(-1)
		exit(0)

	if li[-1] <= prev:
		prev = -1
		cnt += 1

	start = 0
	end = len(li) - 1
	ans = -1
	while(start <= end):
		mid = (start + end)//2
		if li[mid] > prev:
			ans = mid
			end = mid - 1
		else:
			start = mid + 1
	# print(l,ans,li)
	prev = li[ans]

	i += 1

# print(cnt,prev)
final = cnt*len(s) - (len(s) - prev - 1)
print(final)

Submission Info

Submission Time
Task E - Strings of Impurity
User guvi007
Language PyPy3 (2.4.0)
Score 500
Code Size 615 Byte
Status AC
Exec Time 264 ms
Memory 46704 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 45
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45
Case Name Status Exec Time Memory
a01 AC 170 ms 38256 KB
a02 AC 171 ms 38256 KB
a03 AC 171 ms 38256 KB
b04 AC 167 ms 38256 KB
b05 AC 167 ms 38256 KB
b06 AC 169 ms 38320 KB
b07 AC 171 ms 38256 KB
b08 AC 172 ms 38256 KB
b09 AC 166 ms 38256 KB
b10 AC 264 ms 46704 KB
b11 AC 200 ms 46192 KB
b12 AC 193 ms 46064 KB
b13 AC 187 ms 46064 KB
b14 AC 241 ms 45680 KB
b15 AC 246 ms 45680 KB
b16 AC 246 ms 45680 KB
b17 AC 239 ms 43500 KB
b18 AC 230 ms 43372 KB
b19 AC 238 ms 43628 KB
b20 AC 204 ms 43116 KB
b21 AC 210 ms 42860 KB
b22 AC 205 ms 43244 KB
b23 AC 208 ms 43116 KB
b24 AC 203 ms 43116 KB
b25 AC 229 ms 43244 KB
b26 AC 223 ms 42860 KB
b27 AC 213 ms 42988 KB
b28 AC 214 ms 43244 KB
b29 AC 206 ms 43244 KB
b30 AC 214 ms 43884 KB
b31 AC 175 ms 41328 KB
b32 AC 185 ms 39664 KB
b33 AC 176 ms 39664 KB
b34 AC 175 ms 45168 KB
b35 AC 176 ms 39280 KB
b36 AC 207 ms 46192 KB
b37 AC 215 ms 45680 KB
b38 AC 208 ms 46192 KB
b39 AC 200 ms 46064 KB
b40 AC 203 ms 46064 KB
b41 AC 202 ms 46064 KB
b42 AC 183 ms 45552 KB
b43 AC 176 ms 40048 KB
b44 AC 202 ms 46064 KB
b45 AC 199 ms 46064 KB