結果

問題 No.2454 Former < Latter
ユーザー otoshigootoshigo
提出日時 2023-09-01 22:23:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 95,968 KB
実行使用メモリ 6,192 KB
最終ジャッジ日時 2023-09-01 22:23:45
合計ジャッジ時間 2,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 6 ms
5,984 KB
testcase_03 AC 6 ms
5,944 KB
testcase_04 AC 7 ms
6,008 KB
testcase_05 AC 7 ms
6,012 KB
testcase_06 AC 7 ms
6,176 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 7 ms
5,968 KB
testcase_12 WA -
testcase_13 AC 7 ms
5,964 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 6 ms
4,764 KB
testcase_17 AC 46 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 6 ms
6,192 KB
testcase_20 AC 9 ms
5,944 KB
testcase_21 WA -
testcase_22 AC 6 ms
4,380 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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