結果
問題 |
No.1848 Long Prefixes
|
ユーザー |
👑 ![]() |
提出日時 | 2021-12-05 18:48:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,323 bytes |
コンパイル時間 | 2,013 ms |
コンパイル使用メモリ | 197,620 KB |
最終ジャッジ日時 | 2025-01-26 05:25:26 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 RE * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; const ll mod=1e9+7; #define rep(i,a) for (ll i=0;i<a;i++) namespace po167{ //LCP vec[0,n) and vec[i,n) //for all i //O(vec.size()) template<class T> std::vector<int> Z_algo(std::vector<T> &vec){ int n=vec.size(); int ind=1,j=0,k; std::vector<int> ans(n,0); ans[0]=n; while(ind<n){ while(ind+j<n&&vec[j]==vec[ind+j]) j++; ans[ind]=j; if(j==0){ ind++; continue; } k=1; while(k+ind<n&&ans[k]+k<j){ ans[k+ind]=ans[k]; k++; } j-=k; ind+=k; } return ans; } std::vector<int> Z_algo(std::string &vec){ int n=vec.size(); int ind=1,j=0,k; std::vector<int> ans(n,0); ans[0]=n; while(ind<n){ while(ind+j<n&&vec[j]==vec[ind+j]) j++; ans[ind]=j; if(j==0){ ind++; continue; } k=1; while(k+ind<n&&ans[k]+k<j){ ans[k+ind]=ans[k]; k++; } j-=k; ind+=k; } return ans; } } using po167::Z_algo; // rainy ~ 雨に打たれて ~ int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector<ll> A(N); ll sum=0; rep(i,N) cin>>A[i],sum+=A[i]; string S; cin>>S; assert(S.size()==N); assert(sum<=2e6); string T=""; rep(i,N) rep(j,A[i]) T+=S[i]; auto p=Z_algo(T); ll ans=0; for(auto x:p) ans+=x; cout<<ans%mod<<"\n"; }