結果

問題 No.2454 Former < Latter
ユーザー ゼットゼット
提出日時 2023-09-01 22:24:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 680 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 82,732 KB
最終ジャッジ日時 2023-09-01 22:24:34
合計ジャッジ時間 14,153 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,108 KB
testcase_01 AC 70 ms
71,464 KB
testcase_02 AC 680 ms
82,580 KB
testcase_03 AC 647 ms
82,168 KB
testcase_04 AC 662 ms
82,448 KB
testcase_05 AC 654 ms
82,732 KB
testcase_06 AC 633 ms
82,376 KB
testcase_07 AC 617 ms
82,364 KB
testcase_08 AC 362 ms
78,352 KB
testcase_09 AC 451 ms
80,864 KB
testcase_10 AC 481 ms
81,376 KB
testcase_11 AC 671 ms
82,196 KB
testcase_12 AC 639 ms
82,216 KB
testcase_13 AC 677 ms
82,116 KB
testcase_14 AC 646 ms
82,220 KB
testcase_15 AC 587 ms
82,296 KB
testcase_16 AC 580 ms
82,476 KB
testcase_17 AC 525 ms
79,240 KB
testcase_18 AC 276 ms
80,264 KB
testcase_19 AC 622 ms
82,324 KB
testcase_20 AC 620 ms
82,212 KB
testcase_21 AC 359 ms
78,636 KB
testcase_22 AC 476 ms
81,340 KB
testcase_23 AC 449 ms
81,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
mod=67280421310721
for _ in range(Q):
  N=int(input())
  S=input()
  x100=[1]*(N+1)
  for i in range(1,N+1):
    x100[i]=x100[i-1]*100
    x100[i]%=mod
  v=[0]*N
  w=0
  for i in range(N):
    w*=100
    w%=mod
    x=ord(S[i])-ord('a')
    w+=x+1
    w%=mod
    v[i]=w
  result=0
  for i in range(1,N):
    l=0
    r=min(i,N-i)
    r2=r
    while True:
      m=(l+r+1)//2
      a=v[m-1]
      b=v[i+m-1]-v[i-1]*(x100[m])
      b%=mod
      if a==b:
        l=m
      else:
        r=m-1
      if l==r:
        break
    if l==r2:
      if N>2*i:
        result+=1
    else:
      p=ord(S[l])
      q=ord(S[i+l])
      if p<q:
        result+=1
  print(result)
  
0