結果
| 問題 | No.2454 Former < Latter | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-09-01 23:53:24 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 965 bytes | 
| コンパイル時間 | 306 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 80,000 KB | 
| 最終ジャッジ日時 | 2025-01-03 13:23:01 | 
| 合計ジャッジ時間 | 3,736 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 12 WA * 11 | 
ソースコード
import sys,random
from itertools import permutations
from collections import deque
from heapq import *
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N
    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg
for _ in range(int(input())):
    N = int(input())
    S = input()
    Z = Z_algorithm(S)
    ans = 0
    for i in range(1,N):
        if Z[i] == N - i:
            if i < N-i:
                ans += 1
            continue
        if S[Z[i]] < S[Z[i]+i]:
            ans += 1
        else:
            assert S[Z[i]] > S[Z[i]+i]
    print(ans)
            
            
            
        