結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー 👑 KazunKazun
提出日時 2021-06-29 15:47:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,279 ms / 4,000 ms
コード長 1,309 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 120,592 KB
最終ジャッジ日時 2024-04-16 13:28:58
合計ジャッジ時間 24,193 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
65,152 KB
testcase_01 AC 60 ms
65,408 KB
testcase_02 AC 96 ms
77,824 KB
testcase_03 AC 111 ms
78,332 KB
testcase_04 AC 81 ms
77,832 KB
testcase_05 AC 86 ms
78,208 KB
testcase_06 AC 168 ms
78,548 KB
testcase_07 AC 122 ms
78,104 KB
testcase_08 AC 168 ms
78,720 KB
testcase_09 AC 80 ms
77,696 KB
testcase_10 AC 119 ms
78,464 KB
testcase_11 AC 79 ms
77,668 KB
testcase_12 AC 148 ms
80,860 KB
testcase_13 AC 166 ms
80,940 KB
testcase_14 AC 566 ms
83,072 KB
testcase_15 AC 159 ms
81,164 KB
testcase_16 AC 219 ms
82,740 KB
testcase_17 AC 265 ms
82,432 KB
testcase_18 AC 653 ms
84,604 KB
testcase_19 AC 252 ms
80,468 KB
testcase_20 AC 155 ms
79,600 KB
testcase_21 AC 613 ms
82,936 KB
testcase_22 AC 774 ms
96,068 KB
testcase_23 AC 777 ms
94,568 KB
testcase_24 AC 472 ms
88,448 KB
testcase_25 AC 716 ms
102,548 KB
testcase_26 AC 557 ms
96,916 KB
testcase_27 AC 603 ms
105,520 KB
testcase_28 AC 970 ms
106,832 KB
testcase_29 AC 743 ms
103,424 KB
testcase_30 AC 680 ms
106,864 KB
testcase_31 AC 605 ms
93,348 KB
testcase_32 AC 779 ms
117,476 KB
testcase_33 AC 1,011 ms
120,592 KB
testcase_34 AC 1,046 ms
117,984 KB
testcase_35 AC 787 ms
111,796 KB
testcase_36 AC 826 ms
115,352 KB
testcase_37 AC 1,259 ms
87,012 KB
testcase_38 AC 1,242 ms
86,332 KB
testcase_39 AC 1,244 ms
86,400 KB
testcase_40 AC 1,186 ms
86,272 KB
testcase_41 AC 1,279 ms
85,540 KB
testcase_42 AC 59 ms
65,536 KB
testcase_43 AC 173 ms
109,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def H(C,N,K):
    if K in Memo:
        return Memo[K]

    if K==0:
        return 0

    code=ord(C)-ord("a")
    if N==1:
        Memo[K]=X_cnt[code][K]
    else:
        if K<=Len[N-1]:
            Memo[K]=H(C,N-1,K)
        elif K<=Len[N-1]+Y_len:
            Memo[K]=E[code][N-1]+Y_cnt[code][K-Len[N-1]]
        else:
            Memo[K]=2*E[code][N-1]+Y_cnt[code][Y_len]-H(C,N-1,2*Len[N-1]+Y_len-K)
    return Memo[K]

def count(S):
    M=[[0]*len(S) for _ in range(sigma)]
    for i in range(sigma):
        a=Z[i]
        m=M[i]
        for j in range(1,len(S)):
            m[j]=m[j-1]+(1 if S[j]==a else 0)
    return M
#=================================================
import sys
from string import ascii_lowercase as Z

input=sys.stdin.readline
write=sys.stdout.write
X="*"+input()[:-1]; X_len=len(X)-1
Y="*"+input()[:-1]; Y_len=len(Y)-1

Len=[0,X_len]
while Len[-1]<=pow(10,18):
    Len.append(2*Len[-1]+Y_len)

sigma=len(Z)
X_cnt=count(X)
Y_cnt=count(Y)

N=len(Len)-1

E=[[0,X_cnt[a][-1]] for a in range(sigma)]
for a in range(sigma):
    e=E[a]
    y=Y_cnt[a][Y_len]
    for _ in range(2,N+1):
        e.append(2*e[-1]+y)

Q=int(input())
A=[0]*Q

for case in range(Q):
    L,R,C=input().split()
    L=int(L); R=int(R)
    Memo={}
    A[case]=H(C,N,R)-H(C,N,L-1)

write("\n".join(map(str,A)))
0