結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
7,148 KB
testcase_01 AC 97 ms
7,412 KB
testcase_02 AC 146 ms
7,168 KB
testcase_03 AC 145 ms
7,148 KB
testcase_04 AC 99 ms
7,348 KB
testcase_05 AC 128 ms
6,620 KB
testcase_06 AC 139 ms
7,040 KB
testcase_07 AC 98 ms
7,148 KB
testcase_08 AC 137 ms
7,008 KB
testcase_09 AC 139 ms
7,036 KB
testcase_10 AC 95 ms
7,068 KB
testcase_11 AC 130 ms
6,900 KB
testcase_12 AC 134 ms
6,984 KB
testcase_13 AC 95 ms
7,100 KB
testcase_14 AC 143 ms
7,016 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,352 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 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,352 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 1 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 (int i=0;i<a;i++)

const int MAX_N=2e5;
const int MAX_A=1e9;
const int TYPE=26;

//おちこんだりもしたけれど、私はげんきです。
int main() {
	int N;
	cin>>N;
	vector<ll> A(N);
	string S;
	rep(i,N) cin>>A[i];
	cin>>S;
	assert(1<=N&&N<=MAX_N);
	assert((int)(S.size())==N);
	rep(i,N){
		assert(1<=A[i]&&A[i]<=MAX_A);
		assert('a'<=S[i]&&S[i]<='z');
		if(i!=0){
			assert(S[i]!=S[i-1]);
		}
	}
	ll ans=0;
	vector<queue<int>> cha_ind(TYPE);
	vector<ll> dp(N+1);
	rep(i,N) cha_ind[(int)(S[i]-'a')].push(i);
	rep(i,TYPE){
		cha_ind[i].push(N);
		dp[cha_ind[i].front()]++;
	}

	rep(i,N){
		dp[i]%=mod;
		ans=(ans+(dp[i]*A[i])%mod)%mod;
		rep(k,TYPE){
			if(cha_ind[k].front()==i){
				cha_ind[k].pop();
				dp[cha_ind[k].front()]+=dp[i];
			}
			else dp[cha_ind[k].front()]+=(dp[i]*A[i])%mod;
		}
	}
	cout<<ans<<endl;
}

0