結果

問題 No.2454 Former < Latter
ユーザー ntudantuda
提出日時 2023-09-04 23:37:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 669 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 79,712 KB
最終ジャッジ日時 2023-09-04 23:37:22
合計ジャッジ時間 4,602 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,232 KB
testcase_01 WA -
testcase_02 AC 112 ms
79,460 KB
testcase_03 AC 92 ms
79,580 KB
testcase_04 AC 92 ms
79,420 KB
testcase_05 AC 94 ms
79,276 KB
testcase_06 AC 96 ms
79,300 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 98 ms
78,360 KB
testcase_10 AC 106 ms
78,252 KB
testcase_11 AC 96 ms
79,456 KB
testcase_12 WA -
testcase_13 AC 96 ms
79,460 KB
testcase_14 AC 95 ms
79,496 KB
testcase_15 WA -
testcase_16 AC 94 ms
78,944 KB
testcase_17 AC 516 ms
78,620 KB
testcase_18 WA -
testcase_19 AC 102 ms
79,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 106 ms
78,920 KB
testcase_23 AC 104 ms
78,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1;
    j = 0
    A[0] = l = len(S)
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k;
        j -= k
    return A

T = int(input())
for _ in range(T):
    N = int(input())
    S = input()
    A = z_algo(S)
    ans = 0
    for i in range(1, N):
        j = A[i]
        if i < j:
            ans += 1
        elif i + j < N:
            if S[j] < S[i + j]:
                ans += 1
    print(ans)
0