結果

問題 No.2454 Former < Latter
ユーザー SSRSSSRS
提出日時 2023-09-01 21:29:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 510 bytes
コンパイル時間 2,834 ms
コンパイル使用メモリ 218,996 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-09-01 21:29:42
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 12 ms
5,872 KB
testcase_03 AC 12 ms
5,996 KB
testcase_04 AC 12 ms
5,924 KB
testcase_05 AC 12 ms
5,912 KB
testcase_06 AC 11 ms
5,876 KB
testcase_07 AC 11 ms
6,000 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 11 ms
5,884 KB
testcase_12 AC 11 ms
5,920 KB
testcase_13 AC 11 ms
6,008 KB
testcase_14 AC 11 ms
5,864 KB
testcase_15 AC 11 ms
4,624 KB
testcase_16 AC 11 ms
4,496 KB
testcase_17 AC 251 ms
4,384 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 11 ms
5,932 KB
testcase_20 AC 13 ms
5,880 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/string>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> Z = atcoder::z_algorithm(S);
    int ans = 0;
    for (int j = 1; j < N; j++){
      int x = Z[j];
      x = min({x, j, N - j});
      if (x < j && x < N - j){
        if (S[x] < S[j + x]){
          ans++;
        }
      } else if (x < N - j){
        ans++;
      }
    }
    cout << ans << endl;
  }
}
0