結果

問題 No.2454 Former < Latter
ユーザー otoshigootoshigo
提出日時 2023-09-01 22:25:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 96,116 KB
実行使用メモリ 6,148 KB
最終ジャッジ日時 2023-09-01 22:25:58
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 7 ms
5,928 KB
testcase_03 AC 7 ms
6,148 KB
testcase_04 AC 7 ms
6,004 KB
testcase_05 AC 7 ms
5,988 KB
testcase_06 AC 6 ms
5,936 KB
testcase_07 AC 7 ms
5,936 KB
testcase_08 AC 5 ms
4,384 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 8 ms
6,020 KB
testcase_12 AC 7 ms
5,984 KB
testcase_13 AC 8 ms
6,004 KB
testcase_14 AC 7 ms
6,008 KB
testcase_15 AC 7 ms
5,028 KB
testcase_16 AC 6 ms
4,600 KB
testcase_17 AC 42 ms
4,384 KB
testcase_18 AC 6 ms
4,384 KB
testcase_19 AC 7 ms
5,928 KB
testcase_20 AC 10 ms
5,928 KB
testcase_21 AC 8 ms
4,384 KB
testcase_22 AC 7 ms
4,384 KB
testcase_23 AC 7 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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();
    }
}
0