結果

問題 No.1848 Long Prefixes
ユーザー 👑 potato167potato167
提出日時 2021-12-05 18:48:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,323 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 202,532 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2023-09-11 18:01:55
合計ジャッジ時間 8,012 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 27 ms
9,940 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 25 ms
9,124 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 24 ms
8,880 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 25 ms
7,916 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 21 ms
8,064 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 6 ms
5,180 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 3 ms
4,380 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 5 ms
4,764 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,340 KB
testcase_29 RE -
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 8 ms
6,592 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
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<=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";
}
0