結果
| 問題 |
No.1845 Long Substrings
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2021-08-23 21:50:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 159 ms / 2,000 ms |
| コード長 | 983 bytes |
| コンパイル時間 | 2,105 ms |
| コンパイル使用メモリ | 201,272 KB |
| 最終ジャッジ日時 | 2025-01-24 01:40:36 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#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;
}
potato167