結果

問題 No.1845 Long Substrings
ユーザー 沙耶花沙耶花
提出日時 2022-02-18 21:58:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 4,425 ms
コンパイル使用メモリ 268,652 KB
実行使用メモリ 32,428 KB
最終ジャッジ日時 2023-09-11 19:05:51
合計ジャッジ時間 8,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
32,128 KB
testcase_01 AC 83 ms
32,156 KB
testcase_02 AC 132 ms
32,196 KB
testcase_03 AC 134 ms
32,148 KB
testcase_04 AC 89 ms
32,428 KB
testcase_05 AC 109 ms
29,412 KB
testcase_06 AC 123 ms
31,116 KB
testcase_07 AC 88 ms
32,296 KB
testcase_08 AC 128 ms
30,536 KB
testcase_09 AC 129 ms
31,036 KB
testcase_10 AC 72 ms
31,880 KB
testcase_11 AC 117 ms
29,420 KB
testcase_12 AC 126 ms
30,124 KB
testcase_13 AC 85 ms
31,312 KB
testcase_14 AC 133 ms
32,004 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001



int main(){
	
	int n;
	cin>>n;
	vector<long long> a(n);
	rep(i,n)cin>>a[i];
	
	string s;
	cin>>s;
	
	vector nxt(n+1,vector<int>(26,Inf));
	vector<int> cur(26,Inf);
	for(int i=n-1;i>=0;i--){
		nxt[i] = cur;
		cur[s[i]-'a'] = i;
	}
	
	vector<mint> dp(n+1,0);
	set<char> S;
	rep(i,n){
		if(!S.count(s[i]))dp[i] = 1;
		S.insert(s[i]);
	}
	mint ans = 0;
	
	rep(i,n){
		ans += dp[i] * (a[i]);
		rep(j,26){
			if(nxt[i][j]==Inf)continue;
			if(j==s[i]-'a'){
				dp[nxt[i][j]] += dp[i];
			}
			else{
				dp[nxt[i][j]] += dp[i] * a[i];
			}
		}
	}
	
	cout<<ans.val()<<endl;
	
	
	
	return 0;
}
0