結果
| 問題 |
No.1725 [Cherry 3rd Tune D] 無言の言葉
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-10-29 22:46:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 479 ms / 4,000 ms |
| コード長 | 1,486 bytes |
| コンパイル時間 | 630 ms |
| コンパイル使用メモリ | 82,276 KB |
| 実行使用メモリ | 158,464 KB |
| 最終ジャッジ日時 | 2024-10-07 12:28:08 |
| 合計ジャッジ時間 | 12,522 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
x = [ord(c) - 97 for c in input()]
y = [ord(c) - 97 for c in input()]
lx = len(x)
ly = len(y)
def get_acc(d):
l = len(d)
res1 = [[0] * (l + 1) for _ in range(26)]
res2 = [[0] * (l + 1) for _ in range(26)]
for i in range(l):
for j in range(26):
res1[j][i + 1] = res1[j][i]
res1[d[i]][i + 1] += 1
for i in range(l)[::-1]:
for j in range(26):
res2[j][i] = res2[j][i + 1]
res2[d[i]][i] += 1
return res1, res2
axl, axr = get_acc(x)
ayl, ayr = get_acc(y)
sz = []
l = lx
cx = 1
cy = 0
while not sz or sz[-1][-1] < 10 ** 9:
sz.append((l, cx, cy))
l = 2 * l + ly
cx = 2 * cx
cy = 2 * cy + 1
def f(r, c):
flipped = False
tx = ty = 0
for l, cx, cy in sz[::-1]:
if r < l:
if flipped:
flipped = not flipped
continue
tx += cx
ty += cy
r -= l
if r >= ly:
ty += 1
r -= ly
if not flipped:
flipped = not flipped
continue
res = tx * axl[c][-1] + ty * ayl[c][-1]
if flipped:
res += ayr[c][ly - r]
else:
res += ayl[c][r]
return res
res = tx * axl[c][-1] + ty * ayl[c][-1]
if flipped:
res += axr[c][lx - r]
else:
res += axl[c][r]
return res
for _ in range(int(input())):
l, r, c = input().split()
c = ord(c) - 97
print(f(int(r), c) - f(int(l) - 1, c))
Kude