結果

問題 No.1848 Long Prefixes
ユーザー 👑 potato167potato167
提出日時 2021-12-05 18:53:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,323 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 202,348 KB
実行使用メモリ 167,652 KB
最終ジャッジ日時 2023-09-11 18:02:12
合計ジャッジ時間 7,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 26 ms
9,920 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 23 ms
9,088 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 23 ms
8,976 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 24 ms
7,944 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 21 ms
8,144 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 6 ms
5,176 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 3 ms
4,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 5 ms
4,604 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 4 ms
4,412 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 7 ms
6,416 KB
testcase_29 RE -
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 9 ms
6,692 KB
testcase_33 RE -
testcase_34 AC 158 ms
104,888 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 252 ms
167,652 KB
testcase_38 RE -
testcase_39 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<=1e8);
	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";
}
0