結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー SSRSSSRS
提出日時 2021-10-29 21:47:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 4,000 ms
コード長 1,876 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 172,668 KB
実行使用メモリ 29,952 KB
最終ジャッジ日時 2024-04-16 14:34:31
合計ジャッジ時間 7,932 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 13 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 107 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 23 ms
5,424 KB
testcase_17 AC 42 ms
5,504 KB
testcase_18 AC 127 ms
5,376 KB
testcase_19 AC 35 ms
5,376 KB
testcase_20 AC 14 ms
5,376 KB
testcase_21 AC 122 ms
5,376 KB
testcase_22 AC 138 ms
11,776 KB
testcase_23 AC 139 ms
10,880 KB
testcase_24 AC 91 ms
8,576 KB
testcase_25 AC 161 ms
16,512 KB
testcase_26 AC 129 ms
13,824 KB
testcase_27 AC 121 ms
18,560 KB
testcase_28 AC 184 ms
17,792 KB
testcase_29 AC 177 ms
16,896 KB
testcase_30 AC 156 ms
20,096 KB
testcase_31 AC 102 ms
11,008 KB
testcase_32 AC 204 ms
26,368 KB
testcase_33 AC 200 ms
27,008 KB
testcase_34 AC 199 ms
25,216 KB
testcase_35 AC 192 ms
22,656 KB
testcase_36 AC 197 ms
24,704 KB
testcase_37 AC 174 ms
5,376 KB
testcase_38 AC 174 ms
5,376 KB
testcase_39 AC 173 ms
5,376 KB
testcase_40 AC 174 ms
5,376 KB
testcase_41 AC 180 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 43 ms
29,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int dfs(int p, long long L, long long R, char C, int N, int M, vector<vector<int>> &S, vector<vector<int>> &T, vector<long long> &len, vector<vector<long long>> &cnt){
  if (p == 0){
    return S[R][C - 'a'] - S[L][C - 'a'];
  }
  if (L == 0 && R == len[p]){
    return cnt[p][C - 'a'];
  }
  int ans = 0;
  if (L < len[p - 1]){
    ans += dfs(p - 1, L, min(R, len[p - 1]), C, N, M, S, T, len, cnt);
  }
  if (L < len[p - 1] + M && R > len[p - 1]){
    int L2 = max(L, len[p - 1]) - len[p - 1];
    int R2 = min(R, len[p - 1] + M) - len[p - 1];
    ans += T[R2][C - 'a'] - T[L2][C - 'a'];
  }
  if (R >= len[p - 1] + M){
    L -= len[p - 1] + M;
    L = max(L, (long long) 0);
    R -= len[p - 1] + M;
    ans += dfs(p - 1, len[p - 1] - R, len[p - 1] - L, C, N, M, S, T, len, cnt);
  }
  return ans;
}
int main(){
  string X;
  cin >> X;
  string Y;
  cin >> Y;
  int N = X.size();
  int M = Y.size();
  vector<vector<int>> S(N + 1, vector<int>(26, 0));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 26; j++){
      S[i + 1][j] = S[i][j];
    }
    S[i + 1][X[i] - 'a']++;
  }
  vector<vector<int>> T(M + 1, vector<int>(26, 0));
  for (int i = 0; i < M; i++){
    for (int j = 0; j < 26; j++){
      T[i + 1][j] = T[i][j];
    }
    T[i + 1][Y[i] - 'a']++;
  }
  vector<long long> len(30);
  vector<vector<long long>> cnt(30, vector<long long>(26, 0));
  len[0] = N;
  for (int i = 0; i < 26; i++){
    cnt[0][i] = S[N][i];
  }
  for (int i = 0; i < 29; i++){
    len[i + 1] = len[i] * 2 + M;
    for (int j = 0; j < 26; j++){
      cnt[i + 1][j] = cnt[i][j] * 2 + T[M][j];
    }
  }
  int p = 30;
  while (len[p - 1] > 1000000000){
    p--;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int L, R;
    char C;
    cin >> L >> R >> C;
    L--;
    cout << dfs(p, L, R, C, N, M, S, T, len, cnt) << endl;
  }
}
0