結果

問題 No.515 典型LCP
ユーザー sue_charosue_charo
提出日時 2017-05-05 23:53:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,222 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 90,364 KB
最終ジャッジ日時 2023-10-12 10:35:18
合計ジャッジ時間 5,462 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def solve(N, s, M, x, d):
    ans = 0
    s_len = [len(_s) for _s in s]

    i = list(range(1, N + 1))
    j = list(range(1, N + 1))
    for k in range(1, M + 1):
        i[k] = (x // (N - 1)) + 1
        j[k] = (x % (N - 1)) + 1
        if i[k] > j[k]:
            i[k], j[k] = j[k], i[k]
        else:
            j[k] = j[k] + 1
        x = (x + d) % (N * (N - 1))

        ind_i = i[k] - 1
        ind_j = j[k] - 1
        s_i = s[ind_i]
        s_j = s[ind_j]
        n_len = min(s_len[ind_i], s_len[ind_j])
        n_lcp = 0

        for l in range(n_len):
            if s_i[l] == s_j[l]:
                n_lcp += 1
            else:
                break
        ans += n_lcp

    return ans


def main():
    N = II()
    s = [input() for __ in range(N)]
    M, x, d = ILI()
    print(solve(N, s, M, x, d))


if __name__ == "__main__":
    main()
0