結果

問題 No.2454 Former < Latter
ユーザー titiatitia
提出日時 2023-09-02 02:12:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 79,904 KB
最終ジャッジ日時 2023-09-02 02:12:26
合計ジャッジ時間 4,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,516 KB
testcase_01 AC 70 ms
71,180 KB
testcase_02 AC 103 ms
79,756 KB
testcase_03 AC 89 ms
79,076 KB
testcase_04 AC 94 ms
79,856 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 99 ms
79,632 KB
testcase_08 WA -
testcase_09 AC 106 ms
78,720 KB
testcase_10 AC 115 ms
78,988 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 96 ms
79,900 KB
testcase_14 AC 92 ms
79,748 KB
testcase_15 AC 102 ms
79,404 KB
testcase_16 AC 100 ms
79,100 KB
testcase_17 AC 170 ms
79,396 KB
testcase_18 WA -
testcase_19 AC 93 ms
79,904 KB
testcase_20 AC 105 ms
79,692 KB
testcase_21 WA -
testcase_22 AC 118 ms
78,564 KB
testcase_23 AC 146 ms
78,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

T=int(input())
for tests in range(T):
    N=int(input())
    S=input().strip()

    # Z algorithm
    # https://snuke.hatenablog.com/entry/2014/12/03/214243

    LEN=len(S)
    i=1
    j=0
    A=[0]*LEN
    A[0]=LEN

    while i<LEN:
        while i+j<LEN and S[j]==S[i+j]:
            j+=1
        A[i]=j
        
        if j==0:
            i+=1
            continue
        
        k=1
        while i+k<LEN and k+A[k]<j:
            A[i+k]=A[k]
            k+=1
        i+=k
        j-=k

    #print(A)

    ANS=0

    for i in range(1,N):
        L=i
        R=N-i
        
        a=A[i]

        if a==R:
            if L<a:
                ANS+=1
            continue
        if a==L:
            ANS+=1
            continue

        if S[a]<S[i+a]:
            ANS+=1

    print(ANS)

        
        
0