結果
問題 | No.2454 Former < Latter |
ユーザー | chineristAC |
提出日時 | 2023-09-01 23:53:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 965 bytes |
コンパイル時間 | 472 ms |
コンパイル使用メモリ | 87,292 KB |
実行使用メモリ | 84,092 KB |
最終ジャッジ日時 | 2023-09-01 23:53:30 |
合計ジャッジ時間 | 5,616 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
74,776 KB |
testcase_01 | WA | - |
testcase_02 | AC | 151 ms
83,456 KB |
testcase_03 | AC | 144 ms
83,716 KB |
testcase_04 | AC | 143 ms
83,804 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 150 ms
82,424 KB |
testcase_10 | AC | 156 ms
82,412 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 143 ms
83,724 KB |
testcase_14 | AC | 145 ms
83,488 KB |
testcase_15 | WA | - |
testcase_16 | AC | 153 ms
83,132 KB |
testcase_17 | AC | 237 ms
84,092 KB |
testcase_18 | WA | - |
testcase_19 | AC | 141 ms
83,612 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 155 ms
82,120 KB |
testcase_23 | AC | 161 ms
82,792 KB |
ソースコード
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)