結果
| 問題 |
No.2454 Former < Latter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-01 22:25:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 916 bytes |
| コンパイル時間 | 1,619 ms |
| コンパイル使用メモリ | 95,248 KB |
| 最終ジャッジ日時 | 2025-02-16 16:51:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
ソースコード
#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();
}
}