結果
| 問題 | No.2454 Former < Latter | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-09-01 22:23:42 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 915 bytes | 
| コンパイル時間 | 1,438 ms | 
| コンパイル使用メモリ | 94,888 KB | 
| 最終ジャッジ日時 | 2025-02-16 16:50:33 | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 15 WA * 8 | 
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/string>
using namespace std;
using namespace atcoder;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
void solve(){
    int N;
    string S;
    cin>>N>>S;
    vector<int>zl=z_algorithm(S);
    int ans=0;
    for(int i=1;i<N;i++){
        if(S[0]<S[i])ans++;
        else if(S[0]==S[i]){
            int l=zl[i];
            if(i<=l){
                if(i<N-i)ans++;
            }else{
                if(i+l<N-1&&S[l]<S[i+l])ans++;
            }
        }
    }
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}
            
            
            
        