結果

問題 No.1845 Long Substrings
ユーザー 👑 potato167potato167
提出日時 2021-08-23 21:51:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 202,212 KB
実行使用メモリ 8,412 KB
最終ジャッジ日時 2023-10-14 23:13:24
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
8,412 KB
testcase_01 AC 46 ms
8,204 KB
testcase_02 AC 92 ms
8,156 KB
testcase_03 AC 93 ms
8,176 KB
testcase_04 AC 46 ms
8,108 KB
testcase_05 AC 83 ms
7,524 KB
testcase_06 AC 89 ms
7,808 KB
testcase_07 AC 45 ms
8,120 KB
testcase_08 AC 87 ms
7,804 KB
testcase_09 AC 89 ms
7,792 KB
testcase_10 AC 46 ms
8,084 KB
testcase_11 AC 83 ms
7,488 KB
testcase_12 AC 86 ms
7,816 KB
testcase_13 AC 45 ms
7,960 KB
testcase_14 AC 91 ms
7,864 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,356 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)



//おちこんだりもしたけれど、私はげんきです。
int main() {
	int N;
	cin>>N;
	vector<ll> A(N);
	string S;
	rep(i,N) cin>>A[i];
	cin>>S;

	vector<ll> dp(N),prefix_sum(N+1);
	prefix_sum[0]=1;
	ll ans=0;
	vector<int> before_ind(26,-1);
	rep(i,N){
		int ch_num=(S[i]-'a');
		dp[i]=prefix_sum[i];
		if(before_ind[ch_num]!=-1){
			dp[i]-=prefix_sum[before_ind[ch_num]+1];
			dp[i]+=dp[before_ind[ch_num]];
			dp[i]%=mod;
		}
		before_ind[ch_num]=i;
		prefix_sum[i+1]=(prefix_sum[i]+(dp[i]*A[i])%mod)%mod;
	}
	cout<<(mod-1+prefix_sum[N])%mod<<"\n";
	
}

0