結果
問題 | No.2454 Former < Latter |
ユーザー | lemondo |
提出日時 | 2023-09-01 23:20:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 5,368 bytes |
コンパイル時間 | 3,804 ms |
コンパイル使用メモリ | 305,544 KB |
実行使用メモリ | 26,552 KB |
最終ジャッジ日時 | 2024-06-11 05:27:37 |
合計ジャッジ時間 | 4,662 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 35 ms
26,552 KB |
testcase_03 | AC | 17 ms
20,324 KB |
testcase_04 | AC | 17 ms
20,524 KB |
testcase_05 | AC | 26 ms
22,076 KB |
testcase_06 | AC | 18 ms
21,368 KB |
testcase_07 | AC | 30 ms
24,452 KB |
testcase_08 | AC | 11 ms
6,940 KB |
testcase_09 | AC | 11 ms
7,480 KB |
testcase_10 | AC | 16 ms
8,648 KB |
testcase_11 | AC | 19 ms
20,340 KB |
testcase_12 | AC | 19 ms
21,000 KB |
testcase_13 | AC | 19 ms
20,680 KB |
testcase_14 | AC | 18 ms
20,604 KB |
testcase_15 | AC | 13 ms
14,796 KB |
testcase_16 | AC | 13 ms
12,640 KB |
testcase_17 | AC | 69 ms
6,944 KB |
testcase_18 | AC | 11 ms
6,940 KB |
testcase_19 | AC | 19 ms
20,712 KB |
testcase_20 | AC | 31 ms
23,340 KB |
testcase_21 | AC | 22 ms
6,940 KB |
testcase_22 | AC | 16 ms
6,944 KB |
testcase_23 | AC | 15 ms
8,896 KB |
ソースコード
#pragma region Macros #include <bits/stdc++.h> #include <immintrin.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <climits> #include <cmath> #include <complex> #include <cstdarg> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <initializer_list> #include <iomanip> #include <ios> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <streambuf> #include <string> #include <tuple> #include <type_traits> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ll long long #define OVERLOAD(e1, e2, e3, e4, NAME, ...) NAME #define _rep1(i, n) for (long long i = 0; i < n; i++) #define _rep2(i, a, b) for (long long i = a; i < b; ++i) #define _rep3(i, a, b, t) \ for (long long i = a; i * (t / abs(t)) < b * (t / abs(t)); i += t) #define rep(...) OVERLOAD(__VA_ARGS__, _rep3, _rep2, _rep1, _)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define sz(x) (ll) x.size() #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define pcnt __builtin_popcountll #define SORT(v) sort(all(v)) #define UNIQUE(v) \ SORT(v); \ v.erase(unique(v.begin(), v.end()), v.end()); #define COPY(A, B) copy(all(A), B.begin()); #define REV(v) reverse(all(v)) #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) #ifdef LOCAL #define dbg(x) \ cout << __LINE__ << " : " << #x << " = "; \ print(x); #else #define dbg(x) true #endif using namespace std; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vc<T>>; template <typename T> using vvvc = vector<vvc<T>>; template <typename T> bool chmin(T &k, T m) { bool ret = k > m; k = min(k, m); return ret; } template <typename T> bool chmax(T &k, T m) { bool ret = k < m; k = max(k, m); return ret; } template <typename T> inline void print(const vector<T> &v, string s = " ") { for (ll i = 0; i < (ll)v.size(); i++) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n"); } template <typename T, typename S> inline void print(const pair<T, S> &p) { cout << p.first << " " << p.second << endl; } template <typename T> inline void print(const T &x) { cout << x << "\n"; } template <typename T, typename S> inline void print(const vector<pair<T, S>> &v) { for (auto &&p : v) print(p); } void yes(bool a) { cout << (a ? "yes" : "no") << endl; } void YES(bool a) { cout << (a ? "YES" : "NO") << endl; } void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; } template <typename T> T SUM(vc<T> As) { T ret = 0; for (T a : As) ret += a; return ret; } #pragma endregion const ll INF = numeric_limits<long long>::max(); template <typename T = char> struct ZAlgorithm { private: vector<T> s; vector<int> deleted; vector<vector<int>> delete_hist; vector<int> z; queue<int> cur; public: ZAlgorithm() : delete_hist{{}} {} template <typename S> ZAlgorithm(const S &s) : ZAlgorithm() { for (auto &c : s) add(c); } void add(const T &c) { s.emplace_back(c); delete_hist.emplace_back(); deleted.emplace_back(0); z.emplace_back(0); z[0]++; int len = (int)s.size(); if (len == 1) return; if (s[0] == c) cur.emplace(len - 1); else deleted[len - 1] = 1; auto set = [&](int t, int len) { deleted[t] = 1; delete_hist[len].emplace_back(t); z[t] = len - t - 1; }; while (not cur.empty()) { int t = cur.front(); if (deleted[t]) { cur.pop(); } else if (s[len - t - 1] == s.back()) { break; } else { set(t, len); cur.pop(); } } if (not cur.empty()) { int t = cur.front(); for (auto &p : delete_hist[len - t]) { set(p + t, len); } } } int get(int k) const { return deleted[k] ? z[k] : (int)s.size() - k; } int operator[](int k) const { return get(k); } vector<int> get() { vector<int> ret(s.size()); for (int i = 0; i < (int)s.size(); i++) { ret[i] = get(i); } return ret; } }; void solve() { ll N; cin >> N; string S; cin >> S; ZAlgorithm zal(S); ll ans = 0; rep(i, 1, N) { ll k = zal.get(i); if (k > i) ans++; else if (i + k >= N) continue; else { if (i == k) { ans++; } else if (S[k] < S[i + k]) ans++; } } print(ans); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll T; cin >> T; rep(_, T) solve(); }