Submission #7548107
Source Code Expand
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import numpy as np
N = int(input())
S = np.array([ord(x) for x in input().rstrip()],dtype=np.int64)
MOD = 10**9 + 7
base = 1234
def cumprod(arr):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
for n in range(1,Lsq):
arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
for n in range(1,Lsq):
arr[n] *= arr[n-1,-1]; arr[n] %= MOD
return arr.ravel()[:L]
x = np.full(N,base,np.int64); x[0] = 1
power = cumprod(x)
x = np.full(N,pow(base,MOD-2,MOD),np.int64); x[0] = 1
power_inv = cumprod(x)
# rolling hash
H = S * power % MOD
Hcum = H.cumsum() % MOD
def test(n):
# 長さnの文字列で2回現れるものが存在する
x = (Hcum[n-1:] - Hcum[:N-n+1] + H[:N-n+1]) % MOD
x *= power_inv[:N-n+1]
x %= MOD
# 距離n以上離れたところで連番が存在しないといけない
ind = x.argsort(kind='stable')
x = x[ind]
is_left_end = np.zeros(N-n+1,np.bool)
is_left_end[1:] = (x[1:] != x[:-1])
is_left_end[0] = True
is_right_end = np.zeros(N-n+1,np.bool)
is_right_end[:-1] = (x[:-1] != x[1:])
is_right_end[-1] = True
gap = ind[is_right_end] - ind[is_left_end]
return gap.max() >= n
left = 0 # 存在
right = N+1 # 非存在
while left + 1 < right:
mid = (left + right)//2
if test(mid):
left = mid
else:
right = mid
answer = left
print(answer)
Submission Info
| Submission Time | |
|---|---|
| Task | E - Who Says a Pun? |
| User | maspy |
| Language | Python (3.4.3) |
| Score | 0 |
| Code Size | 1519 Byte |
| Status | RE |
| Exec Time | 156 ms |
| Memory | 12920 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-00, 00-sample-01, 00-sample-02 |
| All | 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 01-handmade-08, 01-handmade-09, 01-handmade-10, 01-handmade-11, 01-handmade-12, 02-binary-13, 02-binary-14, 02-binary-15, 02-binary-16, 02-binary-17, 02-binary-18, 02-binary-19, 02-binary-20, 02-binary-21, 02-binary-22, 02-binary-23, 03-BigRandom-24, 03-BigRandom-25, 03-BigRandom-26, 03-BigRandom-27, 03-BigRandom-28, 03-BigRandom-29, 03-BigRandom-30, 03-BigRandom-31, 03-BigRandom-32, 03-BigRandom-33, 03-BigRandom-34, 03-BigRandom-35, 03-BigRandom-36, 03-BigRandom-37, 03-BigRandom-38, 03-BigRandom-39, 03-BigRandom-40, 03-BigRandom-41, 03-BigRandom-42, 03-BigRandom-43, 03-BigRandom-44, 03-BigRandom-45, 03-BigRandom-46, 03-BigRandom-47, 03-BigRandom-48, 03-BigRandom-49, 03-BigRandom-50, 03-BigRandom-51, 03-BigRandom-52, 03-BigRandom-53, 03-BigRandom-54, 04-zero-55, 04-zero-56, 05-AllRandom-57, 05-AllRandom-58, 05-AllRandom-59, 05-AllRandom-60, 05-AllRandom-61, 05-AllRandom-62, 05-AllRandom-63, 05-AllRandom-64, 05-AllRandom-65, 05-AllRandom-66, 05-AllRandom-67, 05-AllRandom-68, 05-AllRandom-69 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-00 | RE | 151 ms | 12428 KiB |
| 00-sample-01 | RE | 149 ms | 12428 KiB |
| 00-sample-02 | RE | 149 ms | 12428 KiB |
| 01-handmade-03 | RE | 153 ms | 12920 KiB |
| 01-handmade-04 | RE | 152 ms | 12792 KiB |
| 01-handmade-05 | RE | 152 ms | 12792 KiB |
| 01-handmade-06 | RE | 153 ms | 12668 KiB |
| 01-handmade-07 | RE | 152 ms | 12796 KiB |
| 01-handmade-08 | RE | 152 ms | 12792 KiB |
| 01-handmade-09 | RE | 152 ms | 12792 KiB |
| 01-handmade-10 | RE | 153 ms | 12668 KiB |
| 01-handmade-11 | RE | 152 ms | 12668 KiB |
| 01-handmade-12 | RE | 152 ms | 12792 KiB |
| 02-binary-13 | RE | 152 ms | 12668 KiB |
| 02-binary-14 | RE | 152 ms | 12668 KiB |
| 02-binary-15 | RE | 152 ms | 12668 KiB |
| 02-binary-16 | RE | 152 ms | 12668 KiB |
| 02-binary-17 | RE | 153 ms | 12668 KiB |
| 02-binary-18 | RE | 151 ms | 12668 KiB |
| 02-binary-19 | RE | 151 ms | 12668 KiB |
| 02-binary-20 | RE | 152 ms | 12668 KiB |
| 02-binary-21 | RE | 151 ms | 12668 KiB |
| 02-binary-22 | RE | 151 ms | 12668 KiB |
| 02-binary-23 | RE | 151 ms | 12668 KiB |
| 03-BigRandom-24 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-25 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-26 | RE | 151 ms | 12668 KiB |
| 03-BigRandom-27 | RE | 152 ms | 12792 KiB |
| 03-BigRandom-28 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-29 | RE | 152 ms | 12792 KiB |
| 03-BigRandom-30 | RE | 151 ms | 12668 KiB |
| 03-BigRandom-31 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-32 | RE | 153 ms | 12792 KiB |
| 03-BigRandom-33 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-34 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-35 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-36 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-37 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-38 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-39 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-40 | RE | 155 ms | 12668 KiB |
| 03-BigRandom-41 | RE | 154 ms | 12668 KiB |
| 03-BigRandom-42 | RE | 155 ms | 12668 KiB |
| 03-BigRandom-43 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-44 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-45 | RE | 153 ms | 12792 KiB |
| 03-BigRandom-46 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-47 | RE | 153 ms | 12792 KiB |
| 03-BigRandom-48 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-49 | RE | 152 ms | 12668 KiB |
| 03-BigRandom-50 | RE | 152 ms | 12792 KiB |
| 03-BigRandom-51 | RE | 153 ms | 12668 KiB |
| 03-BigRandom-52 | RE | 156 ms | 12668 KiB |
| 03-BigRandom-53 | RE | 154 ms | 12668 KiB |
| 03-BigRandom-54 | RE | 154 ms | 12668 KiB |
| 04-zero-55 | RE | 151 ms | 12428 KiB |
| 04-zero-56 | RE | 150 ms | 12428 KiB |
| 05-AllRandom-57 | RE | 153 ms | 12792 KiB |
| 05-AllRandom-58 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-59 | RE | 153 ms | 12792 KiB |
| 05-AllRandom-60 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-61 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-62 | RE | 152 ms | 12668 KiB |
| 05-AllRandom-63 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-64 | RE | 152 ms | 12668 KiB |
| 05-AllRandom-65 | RE | 154 ms | 12668 KiB |
| 05-AllRandom-66 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-67 | RE | 153 ms | 12668 KiB |
| 05-AllRandom-68 | RE | 152 ms | 12796 KiB |
| 05-AllRandom-69 | RE | 153 ms | 12792 KiB |