結果

問題 No.2454 Former < Latter
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-01 21:36:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 4,387 ms
コンパイル使用メモリ 261,348 KB
実行使用メモリ 13,308 KB
最終ジャッジ日時 2023-09-01 21:36:53
合計ジャッジ時間 6,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 48 ms
12,160 KB
testcase_03 AC 45 ms
12,128 KB
testcase_04 AC 50 ms
13,276 KB
testcase_05 AC 50 ms
13,032 KB
testcase_06 AC 51 ms
13,308 KB
testcase_07 AC 45 ms
12,068 KB
testcase_08 AC 48 ms
4,380 KB
testcase_09 AC 37 ms
5,936 KB
testcase_10 AC 44 ms
6,588 KB
testcase_11 AC 46 ms
12,064 KB
testcase_12 AC 49 ms
12,072 KB
testcase_13 AC 39 ms
12,160 KB
testcase_14 AC 40 ms
12,072 KB
testcase_15 AC 60 ms
8,988 KB
testcase_16 AC 59 ms
8,824 KB
testcase_17 AC 61 ms
4,380 KB
testcase_18 AC 51 ms
4,376 KB
testcase_19 AC 67 ms
12,760 KB
testcase_20 AC 70 ms
13,204 KB
testcase_21 AC 53 ms
4,384 KB
testcase_22 AC 41 ms
5,296 KB
testcase_23 AC 41 ms
6,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;

int op(int x, int y) { return min(x, y); }
int e() { return 1e9; }

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> n >> s;

    auto sa = suffix_array(s);
    auto lcp = lcp_array(s, sa);

    segtree<int, op, e> seg(lcp);
    int x = 0;
    while (sa[x]) x++;

    int ans = 0;
    rep(i, 0, x) {
      int l = seg.prod(i, x);
      int a = sa[i];
      int u_len = a;
      int v_len = n - u_len;
      if (l >= u_len && u_len < v_len) {
        ans++;
      }
    }
    rep(i, x + 1, n) {
      int l = seg.prod(x, i);
      int a = sa[i];
      int u_len = a;
      int v_len = n - u_len;
      if (l < u_len || u_len < v_len) {
        ans++;
      }
    }
    cout << ans << "\n";
  }
}
0