結果

問題 No.1845 Long Substrings
ユーザー Carpenters-Cat
提出日時 2022-02-19 19:52:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 731 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 68,040 KB
最終ジャッジ日時 2025-01-28 01:04:12
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main()
{
    int N;
    cin >> N;
    ll num[200010];
    for (int i = 0; i < N; i++) {
        cin >> num[i];
    }
    string s;
    cin >> s;
    int id[26];
    ll dp[26];
    for (int i = 0; i < 26; i++) {
        id[i] = -1;
        dp[i] = 1;
    }
    ll m = 1e9 + 7;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int n = s[i] - 'a';
        for (int j = 0; j < 26; j++) {
            if (j != n && id[j] > id[n]) {
                dp[n] += (dp[j] * num[id[j]]) % m;
                dp[n] %= m;
            }
        }
        id[n] = i;
        ans += (dp[n] * num[i]) % m;
        ans %= m;
    }
    cout << ans << endl;
}
0