結果

問題 No.1845 Long Substrings
ユーザー boatmusclesboatmuscles
提出日時 2022-02-19 13:42:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 41,412 KB
実行使用メモリ 5,380 KB
最終ジャッジ日時 2023-09-11 20:38:31
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
5,312 KB
testcase_01 AC 25 ms
5,380 KB
testcase_02 AC 36 ms
5,364 KB
testcase_03 AC 37 ms
5,352 KB
testcase_04 AC 25 ms
5,304 KB
testcase_05 AC 33 ms
5,148 KB
testcase_06 AC 35 ms
5,180 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 35 ms
5,236 KB
testcase_09 AC 35 ms
5,228 KB
testcase_10 AC 25 ms
5,336 KB
testcase_11 AC 33 ms
5,040 KB
testcase_12 AC 35 ms
5,132 KB
testcase_13 AC 25 ms
5,320 KB
testcase_14 AC 36 ms
5,280 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<atcoder/modint>
using namespace atcoder;
using Mint = modint1000000007;
int main(){
    int N;
    scanf("%d", &N);
    int A[N];
    for(int i = 0; i < N; ++i) scanf("%d", A + i);
    int last[26];
    memset(last,0,sizeof last);
    Mint dp_cum[N+1];
    Mint dp_max[N+1];
    dp_cum[0] = Mint::raw(0);
    dp_max[0] = Mint::raw(1);
    scanf("\n");
    for (int i = 0; i < N; i++)
    {
        char S;
        scanf("%c", &S);
        S -= 'a';
        dp_max[i+1] = dp_cum[i] - dp_cum[last[S]] + dp_max[last[S]];
        dp_cum[i+1] = dp_cum[i] + dp_max[i+1]*Mint::raw(A[i]);
        last[S] = i+1;
    }
    printf("%u\n", dp_cum[N].val());
}
0