Problem:


Score : 500 points

Problem Statement

Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.

Let s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\ldots{s'}_i (the first i characters in s').

Notes

A subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.

Constraints

1 \leq |s| \leq 10^5

1 \leq |t| \leq 10^5

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If there exists an integer i satisfying the following condition, print the minimum such i; otherwise, print -1.

Sample Input 1

contest
son

Sample Output 1

10

t = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest...), so i = 10 satisfies the condition.

On the other hand, t is not a subsequence of the string contestco (the first 9 characters in s'), so i = 9 does not satisfy the condition.

Similarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10.

Sample Input 2

contest
programming

Sample Output 2

-1

t = programming is not a substring of s' = contestcontestcontest.... Thus, there is no integer i satisfying the condition.

Sample Input 3

contest
sentence

Sample Output 3

33

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
contest
son


Sample output:
10

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
s=input()
t=input()
dic={}
n=len(s)
for i in range(n):
	if s[i] in dic:
		dic[s[i]].append(i)
	else:
		dic[s[i]]=[i]
k=0
r=0
for i in t:
	if i in dic:
		a=bisect_left(dic[i],k+0.5)
		if a==len(dic[i]):
			r+=1
			k=dic[i][0]
		else:
			k=dic[i][a]
	else:
		print(-1)
		exit()
print(r*n+k+1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
S = input()
T = input()

set_s = set(S)
set_t = set(T)
len_t = len(T)
if len(set_s & set_t) != len(set_t):
  print(-1)  
else:  
  dic = {c:[] for c in set_s}
  dic_len = {}
  for i,s in enumerate(S):
    dic[s].append(i)
    
  for k in dic:
    dic_len[k] = len(dic[k])
  
  si = 0
  cnt = 0
  for t in T:    
    i = bisect_left(dic[t],si)
    if i == dic_len[t]:
      si = 0
      cnt += 1
      i = bisect_left(dic[t],si)
    
    if dic[t][i] == si:
      si += 1
    else:
      si = dic[t][i]
        
  print(cnt * len(S) + si + 1)

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        #printn(f"{i} ")
        print(nxt[i])

prevpos = nxt[ls-1][ord(t[0])-oa]-1
for i in range(1,len(t)):
    c = ord(t[i])-oa
    nx = nxt[prevpos%ls][c]
    if nx<0:
        print(-1)
        exit()
    prevpos += nx
    #ddprint(f"i {i} pp {prevpos} c {c} ti {t[i]}")
print(prevpos+1)

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        #printn(f"{i} ")
        print(nxt[i])
cur = 0
for i in range(len(t)):
    c = ord(t[i])-oa
    nx = nxt[cur%ls][c]
    if nx<0:
        print(-1)
        exit()
    cur += nx
print(cur+1)

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
prev = [-1]*26
for i in range(2*len(s)):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if 0<=prev[j]<ls and nxt[prev[j]][c]<0:
            nxt[prev[j]][c] = i-prev[j]
    prev[c] = i
cur = 0
for i in range(len(t)):
    c = ord(t[i])-oa
    nx = nxt[cur%ls][c]
    if nx<0:
        print(-1)
        exit()
    cur += nx
print(cur+1)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
cnt=0
mod=-1
for cha in t:
    if cha not in s:
        print(-1)
        exit()
    else:
        idx=s.find(cha)
        if idx<=mod:
            cnt+=1
        mod=idx
print(len(s)*cnt+mod+1)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())

Ls = len(s)
Lt = len(t)

t_set = list(set(t))

tmp = 0
for i in t_set:
  if i in s:
    tmp += 1

if len(t_set) != tmp:
  print(-1)
  exit()

Po_t = []

for i in range(Lt):
  Po_t.append(s.index(t[i]))

ans = 0

for i in range(Lt):
  if Po_t[i] < Po_t[i-1]:
    ans += Ls

ans += Po_t[-1]+1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#別に誰も10^100なんて数が必要とはいってないのだ
def resolve():
    S=input()
    T=input()
    pos=dict()
    ##print(pos)
    for n,str in enumerate(S):
        a=pos.setdefault(str,[])
        ##print(pos)
        ##print(a)
        a.append(n)
        ##print(a)
        pos.update(str=a)
        ##print(pos)
    #print(pos)

    temp=0
    cnt=0
    for t in T:
        try:a=(pos[t])
        except KeyError:print(-1);return
        #print(t,a,len(S))

        for j in a:
            x=j-temp
            if x>0 :cnt+=x;temp=j;break
        else:
            #print("matagi")
            cnt+=len(S)-temp+j
            temp=j
        #print(temp)
        #print(cnt)
    print(cnt+1)

#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
def sn(a):
    return ord(a) - ord("a")
S = input()
T = input()
lt = list(T)
ls = list(S)
set_s = set(list(S))
set_t = set(lt)
if not set_t <= set_s:
    print(-1)
    exit()

cnts = [[] for i in range(26)]
cnts_idx = [0]*26
loops = 0
for i,w in enumerate(ls):
    cnts[sn(w)].append(i)
ans = 0
n = len(S)
prev = -1
for t in lt:
    idx = cnts[sn(t)][cnts_idx[sn(t)]] + loops*n
    if prev>idx:
        loops+=1
        cnts_idx[sn(t)] = 0
    prev = cnts[sn(t)][cnts_idx[sn(t)]] + loops*n
    cnts_idx[sn(t)] = (1+cnts_idx[sn(t)])%len(cnts[sn(t)])

print(prev+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input().strip()
t = input().strip()
chk = [[] for i in range(26)]
ma = [0]*26
ex = [False]*26
for i,si in enumerate(s):
  num = ord(si)-97
  chk[num].append(i+1)
  if not ex[num]:
    ex[num] = True
  ma[num] = i+1
  
import math,bisect
now = 0
ans = 0
l = len(s)
for i,ti in enumerate(t):
  j = i+1
  n = ord(ti)-97
  if not ex[n]:
    ans = -1
    break
  if ans > now*l + ma[n]:
    now = math.ceil((ans-ma[n])/l)
  elif ans == now*l + ma[n]:
    now += 1
  ind = bisect.bisect_left(chk[n],ans-now*l)
  ans = chk[n][ind] + now*l
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input().strip()
t = input().strip()
chk = [[] for i in range(26)]
ma = [0]*26
ex = [False]*26
for i,si in enumerate(s):
  num = ord(si)-97
  chk[num].append(i+1)
  if not ex[num]:
    ex[num] = True
  ma[num] = i+1

import math,bisect
now = 0
ans = 0
l = len(s)
for i,ti in enumerate(t):
  j = i+1
  n = ord(ti)-97
  if not ex[n]:
    ans = -1
    break
  if ans > now*l + ma[n]:
    now = math.ceil((ans-ma[n])/l)
  ind = bisect.bisect_left(chk[n],ans-now*l)
  ans = chk[n][ind] + now*l
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())

for i in range(len(t)):
  if t[i] not in s:
    print("-1")
    quit()

    
ans = 0
q = -1
for j in range(len(t)):
  p = s.index(t[j])
  if q >= p:
    ans += len(s)
    q = p
  else:
    q = p
  #print(ans, p, q)
    
ans += q + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    T = input()
    N = len(S)
    idx = defaultdict(list)
    for i, s in enumerate(S):
        idx[s].append(i)

    x = 0
    n_loop = 0
    for t in T:
        arr = idx[t]
        if len(arr) == 0:
            print(-1)
            return

        i = bisect.bisect_left(arr, x)
        if i < len(arr):
            x = arr[i]
        else:
            n_loop += 1
            x = arr[0]

    print(n_loop * N + x + 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s*=2
next=[[-1]*26 for _ in range(len(s))]
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
from bisect import bisect_left
for i in range(len(s)//2):
	for j in range(26):
		if len(alph[j])>bisect_left(alph[j],i):
			next[i][j]=alph[j][bisect_left(alph[j],i)]
ans=1
now=0
for x in t:
	r=ord(x)-ord("a")
	now=next[now][r]
	if now==-1:
		print(-1)
		exit()
	if now>=len(s)//2:
		ans+=len(s)//2
		now-=len(s)//2
print(ans+now)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s*=2
next=[[-1]*26 for _ in range(len(s))]
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
from bisect import bisect_right
for i in range(len(s)//2):
	for j in range(26):
		if len(alph[j])>bisect_right(alph[j],i):
			next[i][j]=alph[j][bisect_right(alph[j],i)]
ans=1
now=0
for x in t:
	r=ord(x)-ord("a")
	now=next[now][r]
	if now==-1:
		print(-1)
		exit()
	if now>=len(s)//2:
		ans+=len(s)//2
		now-=len(s)//2
print(ans+now)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s*=2
next=[[-1]*26 for _ in range(len(s))]
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
from bisect import bisect_right
for i in range(len(s)//2):
	for j in range(26):
		if len(alph[j])>bisect_right(alph[j],i):
			next[i][j]=alph[j][bisect_right(alph[j],i)]
ans=1
now=0
for x in t:
	r=ord(x)-ord("a")
	now=next[now][r]
	if now>=len(s)//2:
		ans+=len(s)//2
		now-=len(s)//2
print(ans+now)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
num=[0]*26
now=-1
ans=0
for i in range(len(t)):
	p=ord(t[i])-ord("a")
	if len(alph[p])==0:
		print(-1)
		exit()
	if alph[p][num[p]]<now:
		while num[p]<len(alph[p]) and alph[p][num[p]]<now:
			num[p]+=1
	if num[p]>=len(alph[p]):
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	if alph[p][num[p]]>=now:
		ans+=alph[p][num[p]]-now
		now=alph[p][num[p]]
		num[p]+=1
		if num[p]>=len(alph[p]):
			num[p]=0
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
num=[0]*26
now=-1
ans=0
for i in range(len(t)):
	p=ord(t[i])-ord("a")
	if len(alph[p])==0:
		print(-1)
		exit()
	if num[p]>=len(alph[p]):
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	elif alph[p][num[p]]<now:
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	if alph[p][num[p]]>=now:
		ans+=alph[p][num[p]]-now
		now=alph[p][num[p]]
		num[p]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
num=[0]*26
now=0
ans=1
for i in range(len(t)):
	p=ord(t[i])-ord("a")
	if len(alph[p])==0:
		print(-1)
		exit()
	if num[p]>=len(alph[p]):
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	elif alph[p][num[p]]<now:
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	if alph[p][num[p]]>=now:
		ans+=alph[p][num[p]]-now
		now=alph[p][num[p]]
		num[p]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
alph=[[]for _ in range(26)]
for i in range(len(s)):
	alph[ord(s[i])-ord("a")].append(i)
num=[0]*26
now=0
ans=1
for i in range(len(t)):
	p=ord(t[i])-ord("a")
	if len(alph[p])==0:
		print(-1)
		exit()
	if num[p]>=len(alph[p]):
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	elif alph[p][num[p]]<now:
		ans+=len(s)-now+alph[p][0]
		num=[0]*26
		now=alph[p][0]
	if alph[p][num[p]]>now:
		ans+=alph[p][num[p]]-now
		now=alph[p][num[p]]
		num[p]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
from bisect import bisect
points=[[]for i in range(26)]
a=ord("a")
for i,c in enumerate(s):
    points[ord(c)-a].append(i)
for p in points:
    p.append(10**9)

n=len(s)
idx=0
stage=0
for c in t:
    c=ord(c)-a
    p=points[c]
    if len(p)==1:
        stage=0
        idx=-2
        break#あとで帰る
    idx = p[bisect(p,idx)]
    if idx>10**6:
        idx=p[0]
        stage+=1
print(stage*n+idx+1)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    ls = len(s)
    t = input().rstrip()
    lt = len(t)
    alphabet = 'abcdefghijklmnopqrstuvwxyz' #26
    moji = [[] for _ in range(26)]
    for i in range(ls):
        idx = alphabet.index(s[i])
        moji[idx].append(i)
    
    cnt = 0
    res = 0
    while cnt < lt:
        for i in range(cnt, lt):
            idx = alphabet.index(t[i])
            if not moji[idx]:
                print(-1)
                exit()
            if i == cnt:
                now = moji[idx][0]
            else:
                nex = bisect_left(moji[idx], now)
                if nex == len(moji[idx]):
                    res += ls
                    cnt = i
                    break
                now = moji[idx][nex]
        else:
            res += now + 1
            break
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    a=ord('a')
    s=list(map(lambda x:ord(x)-a,input()))
    N=len(s)
    t=list(map(lambda x:ord(x)-a,input()))
    l=[[-1]*26 for _ in range(len(s))]
    for i in range(N-1,-N,-1):
        for j in range(26):
            if l[i-1]!=-1:
                if s[i]==j:
                    l[i-1][j]=i
                else:
                    l[i-1][j]=l[i][j]
    ans=0
    index=N-1
    for a in t:
        n=l[index][a]
        if n==-1:
            print(-1)
            exit()
        if n>index:
            ans+=n-index
        else:
            ans+=n+N-index
        index=n
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    a=ord('a')
    s=list(map(lambda x:ord(x)-a,list(input())))
    t=list(map(lambda x:ord(x)-a,list(input())))
    l=[[-1]*26 for _ in range(len(s))]
    ap=[0]*26
    for i,a in enumerate(s*2):
        for j in range(ap[a],len(s)):
            l[j][a]=i-j
        ap[a]=i
    ans=0
    index=len(s)-1
#    for a in t:
#        n=l[index][a]
#        if n==-1:
#            print(-1)
#            exit()
#        ans+=n
#        index+=n
#        index%=len(s)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    a=ord('a')
    s=list(map(lambda x:ord(x)-a,list(input())))
    t=list(map(lambda x:ord(x)-a,list(input())))
    l=[[-1]*26 for _ in range(len(s))]
    S=s*2
    ap=[0]*26
    for i,a in enumerate(S):
        for j in range(ap[a],len(s)):
            l[j][a]=i
        ap[a]=i
    ans=0
    index=0
    for a in t:
        if l[index][a]==-1:
            print(-1)
            exit()
        ans+=l[index][a]-index
        index=(l[index][a])%len(s)
    print(ans+1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
n = len(s)
m = len(t)
D = {}
E = {}
for i in range(n):
  if s[i] in D:
    D[s[i]][i] = i
  else:
    D[s[i]] = [-1 for _ in range(n)]
    D[s[i]][i] = i
  E[s[i]] = i
for i in D:
  p = E[i]
  for j in range(E[i], E[i] - n, -1):
    if D[i][(j+n)%n] == -1:
      D[i][(j+n)%n] = p
    else:
      p = j
x = 0
p = 0
for i in range(m):
  if t[i] in D:
    y = D[t[i]][p]
    if y < p:
      x += 1
    if i != m - 1:
      p = (y + 1) % n
    else:
      p = y
  else:
    x = -1
    break
if x == -1:
  print(x)
else:
  print(x*n+p+1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

S = input()
T = input()
N = len(S)
NN = len(T)
S = [ord(S[i]) - 97 for i in range(N)]
T = [ord(T[i]) - 97 for i in range(NN)]

ind = [[] for _ in range(26)]
cnt = [0] * 26
for i in range(N):
    s = S[i]
    ind[s].append(i)
    cnt[s] += 1

part = 0
i = 0
j = -1
cond = 0
while i < NN:
    obj = T[i]
    if cnt[obj] == 0:
        cond = 1
        break

    tmp = bisect_left(ind[obj], j)

    if tmp == cnt[obj]:
        j = ind[obj][0]
        part += 1
    else:
        j = ind[obj][tmp]

    i += 1

if cond:
    ans = -1
else:
    ans = N * part + (j + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lis = [[] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord("a")].append(i)
lislen = [len(lis[i]) for i in range(26)]
now = -1
ans = 0
  # print(lis)
for i in range(len(t)):
    if lislen[ord(t[i])-ord("a")] == 0:
        print(-1)
        exit()
    if lis[ord(t[i])-ord("a")][-1] <= now:
        now = lis[ord(t[i])-ord("a")][0]
        ans += len(s)
    elif now < lis[ord(t[i])-ord("a")][0]:
        now = lis[ord(t[i])-ord("a")][0]
    else:
        left = 0
        right = lislen[ord(t[i])-ord("a")]
        mid = 0
        while left < mid:
            mid = (left+right)//2
            if now < lis[ord(t[i])-ord("a")][mid]:
                right = mid
            else:
                left = mid
        now = lis[ord(t[i])-ord("a")][mid]
print(ans+now+1)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lis = [[] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord("a")].append(i)
lislen = [len(lis[i]) for i in range(26)]
now = -1
ans = 0
  # print(lis)
for i in range(len(t)):
    if lislen[ord(t[i])-ord("a")] == 0:
        print(-1)
        exit()
    if lis[ord(t[i])-ord("a")][-1] <= now:
        now = lis[ord(t[i])-ord("a")][0]
        ans += len(s)
    elif now < lis[ord(t[i])-ord("a")][0]:
        now = lis[ord(t[i])-ord("a")][0]
    else:
        left = 0
        right = lislen[ord(t[i])-ord("a")]
        mid = 0
        while mid < right:
            mid = (left+right)//2
            if now < lis[ord(t[i])-ord("a")][mid]:
                right = mid
            else:
                left = mid
        now = lis[ord(t[i])-ord("a")][mid]
print(ans+now+1)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lis = [[] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord("a")].append(i)
lislen = [len(lis[i]) for i in range(26)]
now = -1
ans = 0
  # print(lis)
for i in range(len(t)):
    if lislen[ord(t[i])-ord("a")] == 0:
        print(-1)
        exit()
    if lis[ord(t[i])-ord("a")][-1] < now:
        now = lis[ord(t[i])-ord("a")][0]+1
        ans += len(s)
    elif now < lis[ord(t[i])-ord("a")][0]:
        now = lis[ord(t[i])-ord("a")][0]
    else:
        left = 0
        right = lislen[ord(t[i])-ord("a")]
        mid = 0
        while mid < right:
            mid = (left+right)//2
            if now < lis[ord(t[i])-ord("a")][mid]:
                right = mid
            else:
                left = mid
        now = lis[ord(t[i])-ord("a")][mid]
print(ans+now+1)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lis = [[] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord("a")].append(i)
lislen = [len(lis[i]) for i in range(26)]
now = 0
ans = 0
  # print(lis)
for i in range(len(t)):
    if lislen[ord(t[i])-ord("a")] == 0:
        print(-1)
        exit()
    if lis[ord(t[i])-ord("a")][-1] <= now:
        now = lis[ord(t[i])-ord("a")][0]
        ans += len(s)
    else:
        left = 0
        right = lislen[ord(t[i])-ord("a")]
        mid = right + 1
        while left < mid:
            mid = (left+right)//2
            if now < lis[ord(t[i])-ord("a")][mid]:
                right = mid
            else:
                left = mid
        now = lis[ord(t[i])-ord("a")][mid]
print(ans+now+1)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lis = [[] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord("a")].append(i)
lislen = [len(lis[i]) for i in range(26)]
now = 0
ans = 0
print(lis)
for i in range(len(t)):
    if lislen[ord(t[i])-ord("a")] == 0:
        print(-1)
        exit()
    if lis[ord(t[i])-ord("a")][-1] <= now:
        now = lis[ord(t[i])-ord("a")][0]
        ans += len(s)
    else:
        left = 0
        right = lislen[ord(t[i])-ord("a")]
        mid = right + 1
        while left < mid:
            mid = (left+right)//2
            if now < lis[ord(t[i])-ord("a")][mid]:
                right = mid
            else:
                left = mid
        now = lis[ord(t[i])-ord("a")][mid]
print(ans+now+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from bisect import bisect

def main():
    s = input()
    t = input()
    indices = [[] for i in range(26)]
    n = len(s)
    for i in range(n):
        c = s[i]
        ic = ord(c) - ord("a")
        indices[ic].append(i)
    for i in range(26):
        if not indices[i]:
            continue
        indices[i].append(indices[i][0] + n)

    print(indices)

    ptr = 0
    for c in t:
        ptr += 1
        ic = ord(c) - ord("a")
        if len(indices[ic]) == 0:
            print(-1)
            return
        nptr = bisect(indices[ic], ptr % n)
        ptr += indices[ic][nptr] - (ptr % n)

    print(ptr)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from bisect import bisect

def main():
    s = input()
    t = input()
    indices = [[] for i in range(26)]
    n = len(s)
    for i in range(n):
        c = s[i]
        ic = ord(c) - ord("a")
        indices[ic].append(i)
    for i in range(26):
        if not indices[i]:
            continue
        indices[i].append(indices[i][0] + n)

    ptr = 0
    for c in t:
        # ptr += 1
        ic = ord(c) - ord("a")
        if len(indices[ic]) == 0:
            print(-1)
            return
        nptr = bisect(indices[ic], ptr % n)
        ptr += indices[ic][nptr] - (ptr % n)

    print(ptr + 1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print(-1)
    exit()

#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count+1) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]
    else:
        count = lst1[now][res]
    i += 1

Submission status: Wrong Answer

Solution code:
import bisect

s = input()
t = input()
p = {}
for i in range(len(s)):
    c = s[i]
    if c not in p:
        p[c] = []
    p[c].append(i)

over = 0
ret = 0
for c in t:
    if c not in p:
        print(-1)
        exit(0)
    ind = bisect.bisect_left(p[c], ret)
    if ind < len(p[c]):
        ret = p[c][ind] + 1
    else:
        ret = p[c][0] + 1
        over += 1

Submission status: Wrong Answer

Solution code:


def submit():
    s = input()
    t = input()

    next_char = {}
    char_list = {}

    for i in reversed(range(len(s))):
        c = s[i]
        if c not in next_char.keys():
            next_char[c] = i
            char_list[(c, i)] = -1
        else:
            char_list[(c, i)] = next_char[c]
            next_char[c] = i

    
    init_next_char = next_char.copy()
    loop = 0
    curr = 0
    for c in t:
        # 実現不可能
        if c not in next_char.keys():
            print(-1)
            return
        
        if next_char[c] < curr:
            loop += 1
            curr = 0
            next_char = init_next_char.copy()
        
        curr = next_char[c]
        next_char[c] = char_list[(c, next_char[c])]
    print(loop * len(s) + curr + 1)
        

submit()

Submission status: Wrong Answer

Solution code:
from bisect import bisect
S = input()
T = input()

NS = len(S)
NT = len(T)
alp = {}
for i in range(26):
    alp[chr(97+i)] = i
D = [[] for i in range(26)]
for i in range(NS):
    D[alp[S[i]]].append(i)
inf = float("inf")
for i in range(26):D[i].append(inf)
k = 0
l = 0
ans = -1
for i in range(NT):
    index = alp[T[i]]
    if D[index] == [inf]:break
    b = bisect(D[index],l)
    if D[index][b]==inf:
        k += 1
        l = D[index][0]
    else:
        l = D[index][b]
    if i==NT-1:ans = k*NS+l+1
print(ans)

Submission status: Wrong Answer

Solution code:
#tempt
s=input()
t=input()
ans=0

cnt=[]*26

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = 0
for i in range(len(t)):
  if s.find(t[i]) == -1:
    ans = -1
    break
  else:
    cur = s.find(t[i]) + 1
    ans += cur % len(s)
    s = s[cur:] + s[:cur]
  if ans > 1e100 * (len(s) - 1):
    ans = -1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
s = " " + input()
t = input()
ans = 0
cur = 0
for i in range(len(t)):
  if s.find(t[i]) == -1:
    ans = -1
    break
  else:
    ans += (s.find(t[i]) - cur) % (len(s) - 1)
    cur = s.find(t[i])
  if ans > 1e100 * (len(s) - 1):
    ans = -1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
s = " " + input()
t = input()
ans = 0
cur = 0
for i in range(len(t)):
  if s.find(t[i]) == -1:
    ans = -1
    break
  else:
    ans += (s.find(t[i]) - cur) % (len(s) - 1)
    cur = s.find(t[i])
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()

ss = s+s
dic = {}
for i in range(len(ss)):
  if ss[i] in dic:
    dic[ss[i]].append(i)
  else:
    dic[ss[i]] = [i]
counter = [0, -1]
for ch in t:
  if ch not in dic:
    print(-1)
    exit()
  else:
    for idx in dic[ch]:
      if idx > counter[1]:
        counter[1] = idx%len(s)
        counter[0] += (idx+1)//len(s)
        break
print(counter[0]*len(s) + counter[1] +1)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]].append(i)
repeat = 0
cur_index = -1
for c in t:
  indices = dictionary[c]
  if not indices:
    repeat = 0
    cur_index = -1
    break
  next_index = indices[0]
  for index in indices:
    if index > cur_index:
      next_index = index
      break
  else:
    repeat += 1
  cur_index = next_index
print(len_s * repeat + cur_index + 1)