結果
| 問題 |
No.2454 Former < Latter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-01 21:36:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,448 bytes |
| コンパイル時間 | 4,073 ms |
| コンパイル使用メモリ | 253,320 KB |
| 最終ジャッジ日時 | 2025-02-16 16:20:50 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
ソースコード
#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";
}
}