結果

問題 No.1845 Long Substrings
ユーザー 👑 NachiaNachia
提出日時 2022-02-18 22:40:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 79,312 KB
最終ジャッジ日時 2025-01-28 00:24:30
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;


using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


using modint = atcoder::static_modint<1'000'000'007>;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    string S; cin >> S;

    modint ans = 0;
    modint waiting = 1;
    vector<modint> waitingex(26, 0);

    rep(i,N){
        int c = S[i] - 'a';
        modint catchers = waiting - waitingex[c];
        modint tochu = catchers * (A[i] - 1);
        waitingex[c] = waiting;
        waiting += catchers;
        waiting += tochu; waitingex[c] += tochu;
        ans += catchers + tochu;
    }

    cout << ans.val() << endl;
    return 0;
}




struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0