結果
問題 | No.2454 Former < Latter |
ユーザー | otoshigo |
提出日時 | 2023-09-01 22:25:55 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 916 bytes |
コンパイル時間 | 1,762 ms |
コンパイル使用メモリ | 94,932 KB |
実行使用メモリ | 5,980 KB |
最終ジャッジ日時 | 2025-01-03 09:33:11 |
合計ジャッジ時間 | 2,716 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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(); } }