結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー 👑 KazunKazun
提出日時 2021-06-29 15:47:27
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,440 ms / 4,000 ms
コード長 1,309 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 127,916 KB
最終ジャッジ日時 2023-07-29 06:22:03
合計ジャッジ時間 29,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
80,480 KB
testcase_01 AC 148 ms
80,704 KB
testcase_02 AC 176 ms
82,344 KB
testcase_03 AC 202 ms
83,252 KB
testcase_04 AC 168 ms
81,824 KB
testcase_05 AC 174 ms
82,124 KB
testcase_06 AC 253 ms
83,120 KB
testcase_07 AC 209 ms
82,928 KB
testcase_08 AC 262 ms
85,532 KB
testcase_09 AC 167 ms
81,124 KB
testcase_10 AC 208 ms
83,316 KB
testcase_11 AC 165 ms
81,028 KB
testcase_12 AC 232 ms
85,260 KB
testcase_13 AC 261 ms
87,932 KB
testcase_14 AC 654 ms
87,900 KB
testcase_15 AC 251 ms
85,604 KB
testcase_16 AC 346 ms
88,840 KB
testcase_17 AC 343 ms
86,764 KB
testcase_18 AC 737 ms
91,004 KB
testcase_19 AC 346 ms
87,784 KB
testcase_20 AC 249 ms
84,148 KB
testcase_21 AC 704 ms
87,568 KB
testcase_22 AC 859 ms
102,908 KB
testcase_23 AC 863 ms
101,020 KB
testcase_24 AC 558 ms
93,644 KB
testcase_25 AC 801 ms
108,104 KB
testcase_26 AC 654 ms
101,976 KB
testcase_27 AC 714 ms
111,832 KB
testcase_28 AC 1,069 ms
111,504 KB
testcase_29 AC 843 ms
109,752 KB
testcase_30 AC 775 ms
112,048 KB
testcase_31 AC 707 ms
100,060 KB
testcase_32 AC 901 ms
122,716 KB
testcase_33 AC 1,124 ms
127,916 KB
testcase_34 AC 1,154 ms
124,860 KB
testcase_35 AC 879 ms
116,912 KB
testcase_36 AC 937 ms
120,164 KB
testcase_37 AC 1,440 ms
94,160 KB
testcase_38 AC 1,410 ms
92,980 KB
testcase_39 AC 1,421 ms
94,116 KB
testcase_40 AC 1,415 ms
92,968 KB
testcase_41 AC 1,424 ms
92,000 KB
testcase_42 AC 151 ms
80,492 KB
testcase_43 AC 259 ms
121,536 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