結果

問題 No.2454 Former < Latter
ユーザー chineristACchineristAC
提出日時 2023-09-01 23:52:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2023-09-01 23:52:37
合計ジャッジ時間 5,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
74,652 KB
testcase_01 WA -
testcase_02 AC 177 ms
83,728 KB
testcase_03 AC 143 ms
83,712 KB
testcase_04 AC 143 ms
83,840 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 148 ms
82,524 KB
testcase_10 AC 155 ms
82,564 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 143 ms
83,668 KB
testcase_14 AC 144 ms
83,336 KB
testcase_15 WA -
testcase_16 AC 145 ms
83,516 KB
testcase_17 AC 234 ms
83,300 KB
testcase_18 WA -
testcase_19 AC 141 ms
83,660 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 151 ms
82,352 KB
testcase_23 AC 152 ms
82,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    print(ans)
0