結果
問題 | No.1725 [Cherry 3rd Tune D] 無言の言葉 |
ユーザー | mkawa2 |
提出日時 | 2021-10-30 13:56:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 909 ms / 4,000 ms |
コード長 | 2,270 bytes |
コンパイル時間 | 404 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 321,256 KB |
最終ジャッジ日時 | 2024-10-07 13:39:05 |
合計ジャッジ時間 | 17,010 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,872 KB |
testcase_01 | AC | 40 ms
55,228 KB |
testcase_02 | AC | 63 ms
71,940 KB |
testcase_03 | AC | 107 ms
77,320 KB |
testcase_04 | AC | 58 ms
67,460 KB |
testcase_05 | AC | 64 ms
68,956 KB |
testcase_06 | AC | 123 ms
77,824 KB |
testcase_07 | AC | 106 ms
77,236 KB |
testcase_08 | AC | 112 ms
77,056 KB |
testcase_09 | AC | 53 ms
64,912 KB |
testcase_10 | AC | 105 ms
76,612 KB |
testcase_11 | AC | 54 ms
64,888 KB |
testcase_12 | AC | 162 ms
92,816 KB |
testcase_13 | AC | 164 ms
93,196 KB |
testcase_14 | AC | 277 ms
92,480 KB |
testcase_15 | AC | 173 ms
95,364 KB |
testcase_16 | AC | 183 ms
99,028 KB |
testcase_17 | AC | 210 ms
100,588 KB |
testcase_18 | AC | 293 ms
90,608 KB |
testcase_19 | AC | 188 ms
87,668 KB |
testcase_20 | AC | 138 ms
82,888 KB |
testcase_21 | AC | 280 ms
85,824 KB |
testcase_22 | AC | 448 ms
165,840 KB |
testcase_23 | AC | 442 ms
155,600 KB |
testcase_24 | AC | 350 ms
132,396 KB |
testcase_25 | AC | 573 ms
214,912 KB |
testcase_26 | AC | 464 ms
184,720 KB |
testcase_27 | AC | 533 ms
233,896 KB |
testcase_28 | AC | 599 ms
225,564 KB |
testcase_29 | AC | 568 ms
216,952 KB |
testcase_30 | AC | 615 ms
249,012 KB |
testcase_31 | AC | 398 ms
155,636 KB |
testcase_32 | AC | 907 ms
314,896 KB |
testcase_33 | AC | 909 ms
321,256 KB |
testcase_34 | AC | 877 ms
303,752 KB |
testcase_35 | AC | 809 ms
276,252 KB |
testcase_36 | AC | 877 ms
300,712 KB |
testcase_37 | AC | 353 ms
80,496 KB |
testcase_38 | AC | 349 ms
80,876 KB |
testcase_39 | AC | 344 ms
80,644 KB |
testcase_40 | AC | 334 ms
80,824 KB |
testcase_41 | AC | 339 ms
79,888 KB |
testcase_42 | AC | 41 ms
54,300 KB |
testcase_43 | AC | 322 ms
208,532 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 18446744073709551615 # inf = 4294967295 md = 10**9+7 # md = 998244353 from collections import Counter def cntc(s): res = [] cnt = Counter() res.append(cnt.copy()) for c in s: c = ord(c)-97 cnt[c] += 1 res.append(cnt.copy()) return res s = SI() t = SI() x = len(s) y = len(t) sc = cntc(s) tc = cntc(t) isc = cntc(s[::-1]) itc = cntc(t[::-1]) ww = [x] aa = [1] bb = [0] while ww[-1] < 10**9+5: ww.append(ww[-1]*2+y) aa.append(aa[-1]*2) bb.append(bb[-1]*2+1) # print(ww) # print(aa) # print(bb) def solve(s, c): res = 0 stack = [(len(ww)-1, s, c, False)] while stack: lv, s, c, rev = stack.pop() if s == ww[lv]: res += sc[-1][c]*aa[lv]+tc[-1][c]*bb[lv] elif lv == 0: if rev: res += isc[s][c] else: res += sc[s][c] else: lw = ww[lv-1] if s <= lw: stack.append((lv-1, s, c, False)) else: res += sc[-1][c]*aa[lv-1]+tc[-1][c]*bb[lv-1] if s <= lw+y: if rev: res += itc[s-lw][c] else: res += tc[s-lw][c] else: if rev: res += itc[-1][c] stack.append((lv-1, s-lw-y, c, True)) else: res += tc[-1][c] stack.append((lv-1, s-lw-y, c, True)) return res for _ in range(II()): l, r, c = SI().split() l = int(l)-1 r = int(r) c = ord(c)-97 # print(solve(r, c),solve(l, c)) ans = solve(r, c)-solve(l, c) print(ans)