結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー SSRSSSRS
提出日時 2021-10-29 21:43:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,753 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 172,528 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-04-16 14:30:54
合計ジャッジ時間 42,779 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 935 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 11 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 16 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 127 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 26 ms
5,432 KB
testcase_17 AC 45 ms
5,504 KB
testcase_18 AC 157 ms
5,376 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 152 ms
5,376 KB
testcase_22 AC 2,911 ms
11,776 KB
testcase_23 AC 3,322 ms
10,880 KB
testcase_24 AC 3,178 ms
8,704 KB
testcase_25 AC 2,180 ms
16,640 KB
testcase_26 AC 2,281 ms
13,696 KB
testcase_27 AC 1,339 ms
18,560 KB
testcase_28 AC 2,326 ms
17,664 KB
testcase_29 AC 2,337 ms
17,024 KB
testcase_30 AC 1,696 ms
20,096 KB
testcase_31 AC 2,375 ms
11,136 KB
testcase_32 AC 1,575 ms
26,240 KB
testcase_33 AC 1,526 ms
27,008 KB
testcase_34 AC 1,635 ms
25,216 KB
testcase_35 AC 1,819 ms
22,528 KB
testcase_36 AC 1,671 ms
24,704 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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'];
  }
  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 Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int L, R;
    char C;
    cin >> L >> R >> C;
    L--;
    cout << dfs(29, L, R, C, N, M, S, T, len, cnt) << endl;
  }
}
0