結果

問題 No.2454 Former < Latter
ユーザー umezo
提出日時 2023-09-06 05:37:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 3,625 ms
コンパイル使用メモリ 250,996 KB
最終ジャッジ日時 2025-02-16 18:58:19
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int t;
  cin>>t;
  while(t--){
    int n;
    string s;
    cin>>n>>s;
    vector<int> za=z_algorithm(s);
    int cnt=0;
    for(int i=1;i<n;i++){
      if(s[0]<s[i]) cnt++;
      else if(s[0]>s[i]) continue;
      else{
        if(za[i]<n-i){
          if(s[i+za[i]-1]>s[za[i]-1]) cnt++;
        }
        else if(i<(n+1)/2) cnt++;
      }
    }
    cout<<cnt<<'\n';
  }
    
  return 0;
}
0