結果

問題 No.515 典型LCP
ユーザー ayaoniayaoni
提出日時 2021-08-14 14:03:16
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,551 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 108,776 KB
最終ジャッジ日時 2024-04-15 11:51:03
合計ジャッジ時間 6,131 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 TLE -
testcase_02 RE -
testcase_03 AC 42 ms
52,544 KB
testcase_04 AC 44 ms
52,608 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N = I()
words = [(S(),i) for i in range(N)]
words.sort()

dic = {}
for i in range(N):
    dic[words[i][1]] = i

LCP = [0]*(N-1)
for i in range(N-1):
    count = 0
    for w0,w1 in zip(words[i][0],words[i+1][0]):
        if w0 == w1:
            count += 1
        else:
            break
    LCP[i] = count


class sparse_table():
    def __init__(self,A,func):  # 0-index
        self.N = len(A)
        self.func = func
        self.e = self.N.bit_length()-1
        self.table = [[0]*self.N for _ in range(self.e+1)]
        self.table[0] = A[:]
        for j in range(self.e):
            k = 1 << j
            for i in range(self.N-2*k+1):
                self.table[j+1][i] = self.func(self.table[j][i],self.table[j][i+k])

    def query(self,l,r):  # [l,r)
        f = (r-l).bit_length()-1
        return self.func(self.table[f][l],self.table[f][r-(1<<f)])


ST = sparse_table(LCP,min)
M,x,d = MI()
ans = 0
for _ in range(M):
    i = x//(N-1)+1
    j = x%(N-1)+1
    if i > j:
        i,j = j,i
    else:
        j += 1
    di = dic[i-1]
    dj = dic[j-1]
    ans += ST.query(di,dj)
    x = (x+d) % (N*(N-1))

print(ans)
0