結果
問題 | No.515 典型LCP |
ユーザー | tokusakurai |
提出日時 | 2020-07-14 16:17:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,939 bytes |
コンパイル時間 | 2,671 ms |
コンパイル使用メモリ | 216,184 KB |
実行使用メモリ | 178,284 KB |
最終ジャッジ日時 | 2024-11-17 15:54:49 |
合計ジャッジ時間 | 27,311 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | AC | 941 ms
178,284 KB |
testcase_03 | AC | 2 ms
10,496 KB |
testcase_04 | AC | 2 ms
25,516 KB |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | AC | 816 ms
165,540 KB |
testcase_10 | AC | 823 ms
160,332 KB |
testcase_11 | AC | 816 ms
160,268 KB |
testcase_12 | AC | 810 ms
160,264 KB |
testcase_13 | AC | 794 ms
159,836 KB |
testcase_14 | AC | 701 ms
159,680 KB |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using ld = long double; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const ld EPS = 1e-10; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct Suffix_Array{ const string s; const int n; vector<int> sa; Suffix_Array(const string &str) : s(str+'$'), n(sz(s)){ sa.resize(n); iota(all(sa), 0); sort(all(sa), [&](int a, int b){ return s[a] == s[b] ? a > b : s[a] < s[b]; }); vector<int> rank(n), c(s.begin(), s.end()), cnt(n); for(int len = 1; len < n; len <<= 1){ rep(i, n){ if(i == 0 || c[sa[i-1]] != c[sa[i]]) rank[sa[i]] = i; else{ if(c[sa[i-1]+len/2] != c[sa[i]+len/2]) rank[sa[i]] = i; else rank[sa[i]] = rank[sa[i-1]]; } } iota(all(cnt), 0); copy(all(sa), c.begin()); rep(i, n){ int j = c[i]-len; if(j >= 0) sa[cnt[rank[j]]++] = j; } swap(rank, c); } } int operator [] (int i) const {return sa[i];} int size() const {return n;} }; struct Longest_Common_Prefix_Array{ const Suffix_Array sa; const int n; vector<int> lcp, ord; Longest_Common_Prefix_Array(const Suffix_Array &sa) : sa(sa), n(sa.size()-1){ lcp.assign(n, 0), ord.assign(n+1, 0); lcp[0] = 0; rep(i, n+1) ord[sa[i]] = i; int h = 0; rep(i, n){ int j = sa[ord[i]-1]; if(h > 0) h--; while(max(i, j)+h < n && sa.s[i+h] == sa.s[j+h]) h++; lcp[ord[i]-1] = h; } } int operator [] (int i) const {return lcp[i];} }; template<typename Semigroup> struct Sparse_Table{ Semigroup ope(Semigroup a, Semigroup b){ return min(a, b); } const int n; vector<vector<Semigroup>> st; vector<int> lookup; Sparse_Table(const vector<Semigroup> &table) : n(sz(table)){ st.resize(n); rep(i, n) st[i].pb(table[i]); for(int k = 0; (1<<k) < n; k++){ rep(i, n){ if(i+(1<<k) < n) st[i].pb(ope(st[i][k], st[i+(1<<k)][k])); else st[i].pb(st[i][k]); } } lookup.resize(n+1); lookup[0] = -1; rep2(i, 1, n) lookup[i] = lookup[i/2]+1; } Semigroup query(int l, int r){ int k = lookup[r-l]; return ope(st[l][k], st[r-(1<<k)][k]); } }; int main(){ ll N; cin >> N; string s[N]; rep(i, N) cin >> s[i]; int n = 0, pos[N]; rep(i, N) pos[i] = n, n += sz(s[i]); string S; rep(i, N) S += s[i]; Suffix_Array sa(S); vector<int> ord(n+1); rep(i, n+1) ord[sa[i]] = i; Longest_Common_Prefix_Array lcp(sa); vector<int> table(n); rep(i, n) table[i] = lcp[i]; Sparse_Table<int> st(table); int M; ll x, d; cin >> M >> x >> d; ll ans = 0; rep(i, M){ int a = x/(N-1), b = x%(N-1); if(a > b) swap(a, b); else b++; int tmp = min(sz(s[a]), sz(s[b])); a = ord[pos[a]], b = ord[pos[b]]; if(a > b) swap(a, b); chmin(tmp, st.query(a, b)); ans += tmp; x += d, x %= N*(N-1); } cout << ans << endl; }