結果

問題 No.1845 Long Substrings
ユーザー ruthen71
提出日時 2022-02-18 23:13:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 173,072 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-06-29 09:49:00
合計ジャッジ時間 3,379 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) begin(x), end(x)
template <class T> using V = vector<T>;

#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;
ostream &operator<<(ostream &os, const mint &p) { return os << p.val(); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<ll> A(N);
    rep(i, N) cin >> A[i];
    string S;
    cin >> S;
    V<int> B(N);
    rep(i, N) B[i] = S[i] - 'a';
    V<mint> sig(26, 0);
    rep(i, N) {
        mint nx = A[i];
        rep(k, 26) {
            if (k == B[i]) continue;
            nx += sig[k] * A[i];
        }
        sig[B[i]] += nx;
    }
    mint ans = 0;
    rep(k, 26) ans += sig[k];
    cout << ans.val() << '\n';
    return 0;
}
0