結果

問題 No.1845 Long Substrings
ユーザー ruthenruthen
提出日時 2022-02-18 23:12:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 171,720 KB
実行使用メモリ 5,816 KB
最終ジャッジ日時 2023-09-11 20:03:22
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
5,784 KB
testcase_01 AC 28 ms
5,808 KB
testcase_02 AC 40 ms
5,752 KB
testcase_03 AC 40 ms
5,760 KB
testcase_04 AC 28 ms
5,772 KB
testcase_05 AC 35 ms
5,340 KB
testcase_06 AC 38 ms
5,684 KB
testcase_07 AC 28 ms
5,816 KB
testcase_08 AC 39 ms
5,516 KB
testcase_09 AC 38 ms
5,728 KB
testcase_10 AC 27 ms
5,744 KB
testcase_11 AC 36 ms
5,624 KB
testcase_12 AC 37 ms
5,476 KB
testcase_13 AC 27 ms
5,780 KB
testcase_14 AC 40 ms
5,552 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    V<ll> sc(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;
        sc[B[i]] += A[i];
        show(nx);
        show(sig);
    }
    mint ans = 0;
    rep(k, 26) ans += sig[k];
    cout << ans.val() << '\n';
    return 0;
}
0