結果
問題 | No.1018 suffixsuffixsuffix |
ユーザー | n_vip |
提出日時 | 2020-04-03 23:00:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,264 bytes |
コンパイル時間 | 1,929 ms |
コンパイル使用メモリ | 156,228 KB |
実行使用メモリ | 54,968 KB |
最終ジャッジ日時 | 2024-07-03 05:34:40 |
合計ジャッジ時間 | 8,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 71 ms
26,080 KB |
testcase_11 | AC | 70 ms
26,184 KB |
testcase_12 | AC | 64 ms
26,020 KB |
testcase_13 | AC | 64 ms
25,920 KB |
testcase_14 | WA | - |
testcase_15 | AC | 235 ms
52,748 KB |
testcase_16 | WA | - |
testcase_17 | AC | 217 ms
52,736 KB |
testcase_18 | AC | 224 ms
52,724 KB |
testcase_19 | WA | - |
testcase_20 | AC | 18 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | AC | 19 ms
5,504 KB |
testcase_23 | AC | 20 ms
5,632 KB |
testcase_24 | WA | - |
testcase_25 | AC | 249 ms
52,972 KB |
testcase_26 | AC | 234 ms
52,588 KB |
testcase_27 | WA | - |
testcase_28 | AC | 232 ms
52,608 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 19 ms
5,504 KB |
testcase_36 | WA | - |
testcase_37 | AC | 255 ms
52,936 KB |
ソースコード
#include <string> #include <vector> #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> #include<functional> #include<list> #include<deque> #include<bitset> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring> #include<sstream> #include<complex> #include<iomanip> #include<numeric> #include<cassert> #include<random> #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X)) #define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X)) #define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X)) #define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) #define Endl endl #define NL <<"\n" using namespace std; using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; template<class T> using vv=vector<vector<T>>; template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;} template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;} //#undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif #ifdef __cpp_init_captures template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);} template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));} #endif const ll MOD=1e9+7; //998244353 struct RMQ{ const int INF=MOD; vv<int> mn; int D; void upd(const vector<int> &v){ mn.clear(); D=0; for(int i=v.size();i;i/=2) ++D; mn.resize(D+1,vector<int>(1<<D+1,INF)); rep(i,v.size()) mn[D][i]=v[i]; rrep(i,D)rep(j,1<<D){ int b=(j>>(D-i)|1)<<(D-i); //assert(b!=(1<<D) || !(j>>(D-i)&1)); mn[i][j]=j>>(D-i)&1?get(b,j+1):get(j,b); } } RMQ(){} RMQ(const vector<int> &v){upd(v);} int get(int l,int r){ //[l,r) --r; if(l==r)return mn[D][l]; if(l>r) return INF; int d=__builtin_clz(l^r)+D-31; return min(mn[d][l],mn[d][r]); } }; // Larsson-Sadakane's Suffix array Construction: O(n (log n)^2) struct SA:public vector<int>{ struct SAComp { const int h; const vector<int> &g; SAComp(int h, const vector<int> &g) : h(h), g(g) {} bool operator() (int a, int b) { return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a+h] < g[b+h]; } }; vector<int> inv,lcp; string str; RMQ rmq; SA(){} SA(const string &str):str(str){build(str);} void build(const string &s){ str=s; buildSA(); buildLCP(); rmq.upd(lcp); inv.resize(size()); rep(i,size()) inv[at(i)]=i; } void buildSA(){ int n=str.size(); vector<int> g(n+1),b(n+1); resize(n+1); rep(i,n+1) at(i)=i, g[i]=str[i]; sort(all(*this), SAComp(0,g)); for(int h=1; b[n]!=n; h*=2) { SAComp comp(h,g); sort(all(*this),comp); rep(i,n) b[i+1]=b[i]+comp(at(i),at(i+1)); rep(i,n+1) g[at(i)]=b[i]; } } void buildLCP(){ int n=str.size(); int h=0; vector<int> b(n+1); lcp.resize(n+1); rep(i,n+1) b[at(i)]=i; rep(i,n+1) { if(b[i]){ for (int j=at(b[i]-1); j+h<n && i+h<n && str[j+h]==str[i+h]; ++h); lcp[b[i]]=h; } else lcp[b[i]]=-1; if (h>0) --h; } } int getMn(int l,int r){return rmq.get(l+1,r+1);} }; ostream& operator<<(ostream &os,const SA &sa){ rep(i,sa.size()) os<<sa.lcp[i]<<"\t"<<sa.str.substr(sa[i])<<endl; return os; } void kmp(const string &str,vector<int> &re){ re.resize(str.size()+1); re[0]=-1; int j=-1; rep(i,str.size()){ while(j>=0 && str[i]!=str[j]) j=re[j]; re[i+1]=++j; } } vector<ll> solve(string s,ll m,vector<ll> inds){ const int q=inds.size(); const int n=s.size(); if(m==1){ SA sa(s); vector<ll> re(q); rep(i,q) re[i]=sa[inds[i]+1]; return re; } SA sa(s+s); out(sa,1); vector<pll> ps; ll cur=0; for(auto x:sa){ if(x==2*n) continue; ps.eb(cur,x); if(x<n) cur+=m-1; else ++cur; } ps.eb(cur,-1); assert(cur==n*m); out(ps,1); vector<ll> re(q); ll ad=(m-2ll)*n; rep(i,q){ auto ind=inds[i]; auto p=*(upper_bound(all(ps),pll(ind,MOD))-1); out(p,1); auto dif=ind-p.X; re[i]=p.Y+ad-n*dif; } return re; } vector<ll> naive(string s,ll m,vector<ll> inds){ string ss; rep(_,m) ss+=s; return solve(ss,1,inds); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(0); if(0){ rep(_,10000){ const int n=rand()%10+1; string s(n,'.'); for(char &c:s) c=rand()%1+'a'; // s+=s; s+=s; // s.resize(rand()%s.size()+1); int m=10; vector<ll> inds(s.size()*m); iota(all(inds),0); auto exp=naive(s,m,inds); auto act=naive(s,m,inds); if(exp!=act){ out(s,m,inds,exp,act,1); return 0; } } return 0; } ll n,m,q; cin>>n>>m>>q; string s; cin>>s; vector<ll> inds(q); for(auto &x:inds) cin>>x, --x; vector<int> kmp; ::kmp(s,kmp); out(kmp,1); if(kmp.back() && n%kmp.back()==0){ s=s.substr(0,n-kmp.back()); m*=n/kmp.back(); } auto re=solve(s,m,inds); rep(i,q) cout<<re[i]+1<<" \n"[i+1==q]; return 0; }