結果

問題 No.2454 Former < Latter
ユーザー sotanishysotanishy
提出日時 2023-09-01 21:49:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 80,432 KB
最終ジャッジ日時 2023-09-01 21:50:03
合計ジャッジ時間 4,168 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,312 KB
testcase_01 WA -
testcase_02 AC 109 ms
79,896 KB
testcase_03 AC 97 ms
79,584 KB
testcase_04 AC 94 ms
79,680 KB
testcase_05 AC 95 ms
79,660 KB
testcase_06 AC 96 ms
79,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 97 ms
78,408 KB
testcase_10 AC 103 ms
78,372 KB
testcase_11 AC 98 ms
79,664 KB
testcase_12 WA -
testcase_13 AC 99 ms
79,604 KB
testcase_14 AC 100 ms
79,556 KB
testcase_15 WA -
testcase_16 AC 98 ms
78,984 KB
testcase_17 AC 194 ms
80,432 KB
testcase_18 WA -
testcase_19 AC 93 ms
79,664 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 103 ms
78,468 KB
testcase_23 AC 102 ms
78,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


def z_array(s):
    n = len(s)
    z = [0] * n
    z[0] = n
    l = r = 0
    for i in range(1, n):
        k = i - l
        if i <= r and z[k] < r - i + 1:
            z[i] = z[k]
        else:
            l = i
            if i > r:
                r = i
            while r < n and s[r - l] == s[r]:
                r += 1
            r -= 1
            z[i] = r - l + 1
    return z


T = int(input())
for _ in range(T):
    N = int(input())
    S = input().rstrip()
    z = z_array(S)
    cnt = 0
    for i in range(1, N):
        if z[i] > i or (i+z[i] < N and S[z[i]] < S[i+z[i]]):
            cnt += 1
    print(cnt)
0