結果
問題 | No.515 典型LCP |
ユーザー | ayaoni |
提出日時 | 2021-08-14 14:04:01 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,589 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,356 KB |
実行使用メモリ | 109,292 KB |
最終ジャッジ日時 | 2024-04-15 11:51:36 |
合計ジャッジ時間 | 7,812 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | AC | 324 ms
77,024 KB |
testcase_03 | AC | 40 ms
52,824 KB |
testcase_04 | AC | 40 ms
53,744 KB |
testcase_05 | AC | 197 ms
74,256 KB |
testcase_06 | AC | 238 ms
76,732 KB |
testcase_07 | AC | 223 ms
76,968 KB |
testcase_08 | AC | 273 ms
76,628 KB |
testcase_09 | AC | 242 ms
77,580 KB |
testcase_10 | AC | 253 ms
77,272 KB |
testcase_11 | AC | 246 ms
77,236 KB |
testcase_12 | AC | 250 ms
77,324 KB |
testcase_13 | AC | 217 ms
76,424 KB |
testcase_14 | AC | 98 ms
76,960 KB |
testcase_15 | AC | 175 ms
71,764 KB |
testcase_16 | AC | 178 ms
72,704 KB |
ソースコード
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] if di > dj: di,dj = dj,di ans += ST.query(di,dj) x = (x+d) % (N*(N-1)) print(ans)