提出 #6575399


ソースコード 拡げる

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = input().rstrip()
T = input().rstrip()

S,T

# Sの方が長くする
LS = len(S)
LT = len(T)
n = (LT + (-LT) % LS) // LS
S *= (n+1)
S = S[:LS+LT]

MOD = 10 ** 16 + 61
base = 12345
base_inv = pow(base,MOD-2,MOD) 
power = [1] * (LS+LT)
power_inv = [1] * (LS+LT)
for n in range(1,LS+LT):
    power[n] = power[n-1] * base % MOD
    power_inv[n] = power_inv[n-1] * base_inv % MOD

def to_rolling_hash(S):
    ret = [0] * len(S)
    for i,s in enumerate(S):
        ret[i] = (ret[i-1] + power[i] * ord(s)) % MOD
    return ret

S_hash = to_rolling_hash(S) + [0]
T_hash = to_rolling_hash(T)[-1] # 文字列全体

can_start = [(S_hash[i + LT - 1] - S_hash[i - 1]) * power_inv[i] % MOD == T_hash for i in range(LS)]

INF = 10 ** 18
visited = [False] * LS
dp = [None] * LS

def dfs(i):
    if visited[i]:
        if dp[i] is None:
            # ループ
            return INF
        return dp[i]
    visited[i] = True
    if not can_start[i]:
        dp[i] = 0
        return 0
    x = dfs((i + LT) % LS) + 1
    dp[i] = x
    return x

answer = max(dfs(i) for i in range(LS))

if answer >= INF:
    answer = -1

print(answer)

提出情報

提出日時
問題 F - Strings of Eternity
ユーザ maspy
言語 PyPy3 (2.4.0)
得点 0
コード長 1253 Byte
結果 TLE
実行時間 2135 ms
メモリ 548960 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 600
結果
AC × 3
AC × 65
TLE × 5
セット名 テストケース
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56, b57, b58, b59, b60, b61, b62, b63, b64, b65, b66, b67, b68, b69, b70
ケース名 結果 実行時間 メモリ
a01 AC 162 ms 38296 KiB
a02 AC 159 ms 38256 KiB
a03 AC 163 ms 38256 KiB
b04 AC 161 ms 38256 KiB
b05 AC 161 ms 38256 KiB
b06 AC 161 ms 38256 KiB
b07 AC 161 ms 38256 KiB
b08 AC 161 ms 38256 KiB
b09 AC 162 ms 38256 KiB
b10 AC 160 ms 38256 KiB
b11 AC 160 ms 38256 KiB
b12 AC 1537 ms 358180 KiB
b13 TLE 2133 ms 539200 KiB
b14 TLE 2134 ms 548960 KiB
b15 AC 709 ms 199620 KiB
b16 TLE 2135 ms 529828 KiB
b17 AC 1501 ms 357856 KiB
b18 AC 1503 ms 357924 KiB
b19 TLE 2134 ms 526628 KiB
b20 AC 1512 ms 357856 KiB
b21 AC 1510 ms 357824 KiB
b22 AC 1506 ms 358020 KiB
b23 TLE 2131 ms 508736 KiB
b24 AC 1425 ms 290352 KiB
b25 AC 1520 ms 357856 KiB
b26 AC 1174 ms 266788 KiB
b27 AC 1526 ms 357824 KiB
b28 AC 1894 ms 449088 KiB
b29 AC 1600 ms 365172 KiB
b30 AC 1551 ms 355392 KiB
b31 AC 1522 ms 357824 KiB
b32 AC 1537 ms 357924 KiB
b33 AC 1535 ms 357924 KiB
b34 AC 1529 ms 357928 KiB
b35 AC 1503 ms 357824 KiB
b36 AC 1106 ms 281436 KiB
b37 AC 1504 ms 357856 KiB
b38 AC 1504 ms 357984 KiB
b39 AC 1508 ms 357952 KiB
b40 AC 1505 ms 357856 KiB
b41 AC 1506 ms 357856 KiB
b42 AC 1515 ms 357824 KiB
b43 AC 1611 ms 377920 KiB
b44 AC 1520 ms 357856 KiB
b45 AC 1519 ms 360768 KiB
b46 AC 1517 ms 357824 KiB
b47 AC 1577 ms 370016 KiB
b48 AC 1116 ms 277208 KiB
b49 AC 1514 ms 357856 KiB
b50 AC 1505 ms 357832 KiB
b51 AC 1569 ms 360632 KiB
b52 AC 1506 ms 357592 KiB
b53 AC 1526 ms 350520 KiB
b54 AC 1513 ms 357872 KiB
b55 AC 1566 ms 349620 KiB
b56 AC 812 ms 185248 KiB
b57 AC 805 ms 192040 KiB
b58 AC 301 ms 84980 KiB
b59 AC 183 ms 42992 KiB
b60 AC 361 ms 114532 KiB
b61 AC 229 ms 59740 KiB
b62 AC 271 ms 79188 KiB
b63 AC 809 ms 194704 KiB
b64 AC 1511 ms 357928 KiB
b65 AC 1506 ms 357856 KiB
b66 AC 1501 ms 357824 KiB
b67 AC 1512 ms 357824 KiB
b68 AC 1514 ms 357856 KiB
b69 AC 1517 ms 357932 KiB
b70 AC 1504 ms 357824 KiB