結果

問題 No.515 典型LCP
ユーザー sue_charosue_charo
提出日時 2017-05-05 22:54:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,416 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 25,152 KB
最終ジャッジ日時 2023-10-12 10:03:01
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 32 ms
10,120 KB
testcase_04 AC 32 ms
10,112 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 makeQuery(N, M, x, d):
    query = []
    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))
    for q in range(1, N):
        query.append((i[q], j[q]))

    return query


def solve(N, s, M, x, d):
    query = makeQuery(N, M, x, d)
    ans = 0
    for q in query:
        s_i = s[q[0] - 1]
        s_j = s[q[1] - 1]
        n_len = min(len(s_i), len(s_j))
        l_lcp = []
        n_lcp = 0
        for i in range(n_len):
            if s_i[i] == s_j[i]:
                n_lcp += 1
            else:
                l_lcp.append(n_lcp)
                break
        else:
            l_lcp.append(n_lcp)
        ans += max(l_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