結果

問題 No.1845 Long Substrings
ユーザー auauaauaua
提出日時 2022-02-19 01:36:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 168,684 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2023-09-11 20:26:58
合計ジャッジ時間 4,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
6,632 KB
testcase_01 AC 37 ms
6,592 KB
testcase_02 AC 85 ms
6,560 KB
testcase_03 AC 83 ms
6,556 KB
testcase_04 AC 38 ms
6,544 KB
testcase_05 AC 75 ms
6,148 KB
testcase_06 AC 81 ms
6,288 KB
testcase_07 AC 37 ms
6,560 KB
testcase_08 AC 79 ms
6,488 KB
testcase_09 AC 80 ms
6,240 KB
testcase_10 AC 37 ms
6,596 KB
testcase_11 AC 76 ms
6,244 KB
testcase_12 AC 77 ms
6,296 KB
testcase_13 AC 36 ms
6,504 KB
testcase_14 AC 81 ms
6,820 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,504 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <unordered_set>
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=INF;
const ll MAX=1000010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;



void solve(){
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    string s;cin>>s;
    vector<ll>la(26,-1);
    vector<ll>x(26);
    ll ans=0;
    vector<ll>dp(n+1);
    ll inv2=(mod+1)/2;
    dp[0]=1;
    REP(i,1,n+1){
        ll z=dp[i-1];
        if(la[s[i-1]-'a']>=0)z-=x[s[i-1]-'a'];
        ans=(ans+z*a[i-1]%mod)%mod;
        dp[i]=(dp[i-1]+z*a[i-1]%mod)%mod;
        la[s[i-1]-'a']=i;
        x[s[i-1]-'a']=dp[i]-z;
    }
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

signed main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    solve();
}
0