結果
問題 | No.1845 Long Substrings |
ユーザー |
|
提出日時 | 2022-02-18 23:12:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 1,739 ms |
コンパイル使用メモリ | 175,304 KB |
実行使用メモリ | 5,888 KB |
最終ジャッジ日時 | 2024-06-29 09:48:36 |
合計ジャッジ時間 | 3,744 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#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; }