結果

問題 No.1845 Long Substrings
ユーザー t_mkt_mk
提出日時 2022-03-16 17:47:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 172,272 KB
実行使用メモリ 28,024 KB
最終ジャッジ日時 2023-10-24 23:03:59
合計ジャッジ時間 5,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
28,024 KB
testcase_01 AC 93 ms
28,024 KB
testcase_02 AC 153 ms
28,024 KB
testcase_03 AC 175 ms
28,024 KB
testcase_04 AC 126 ms
28,024 KB
testcase_05 AC 101 ms
25,536 KB
testcase_06 AC 126 ms
26,900 KB
testcase_07 AC 115 ms
27,996 KB
testcase_08 AC 166 ms
26,608 KB
testcase_09 AC 170 ms
26,900 KB
testcase_10 AC 61 ms
27,744 KB
testcase_11 AC 133 ms
25,544 KB
testcase_12 AC 162 ms
26,084 KB
testcase_13 AC 117 ms
27,180 KB
testcase_14 AC 172 ms
27,472 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n);i++)
int mod = 1e9+7;
int main(){
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  string s;
  cin >> s;
  s = 'x' + s;
  vector<int> S(++n);
  rep(i,n) S[i] = s[i] - 'a';
  int next_pos[n+1][26];
  rep(i,26) next_pos[n][i] = -1;
  ll dp[n] =  {0};

  for(int i = n-1;i >= 0;i--){
    dp[i] = 1;
    rep(j,26){
      if(i < n-1 && S[i+1] == j)next_pos[i][j] = i+1;
      else next_pos[i][j] = next_pos[i+1][j];
      if(next_pos[i][j] == -1)continue;
      dp[i] += dp[next_pos[i][j]];
      dp[i] %= mod;
    }
    ll sum = dp[i] - 1;
    if(next_pos[i][S[i]] != -1)sum -= dp[next_pos[i][S[i]]];
    sum += mod;
    sum %= mod;
    if(i > 0){
      dp[i] = dp[i] + (sum+1)*(A[i-1]-1);
      dp[i]%= mod;
    }

  }
  dp[0]--;
  cout << dp[0] << endl;
  return 0;
}
0