結果
問題 | No.1845 Long Substrings |
ユーザー |
![]() |
提出日時 | 2023-08-16 21:01:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 120 ms / 2,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 5,152 ms |
コンパイル使用メモリ | 309,840 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-25 11:15:31 |
合計ジャッジ時間 | 8,189 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include<bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint=modint1000000007; using ll=long long; using pp=pair<int,int>; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n;cin>>n; vc<ll>v(n); rep(i,n)cin>>v[i]; sr s;cin>>s; vc<mint>dp(n+1,0); dp[0]=1; //vc<mint>dx(n+1,0); vc<int>last(26,-1); rep(i,n){ auto&x=dp[i+1]; x=dp[i]*(v[i]+1); int t=last[s[i]-'a']; if(t!=-1)x-=(dp[t]-(dp[t]-dp[t-1])/v[t-1])*(v[i]); last[s[i]-'a']=i+1; } mint ans=dp[n]-1; cout<<ans.val(); }