結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 942 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 3 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 122 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 25 ms
5,428 KB
testcase_17 AC 43 ms
5,632 KB
testcase_18 AC 159 ms
5,376 KB
testcase_19 AC 42 ms
5,376 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 151 ms
5,376 KB
testcase_22 AC 2,926 ms
11,904 KB
testcase_23 AC 3,333 ms
11,008 KB
testcase_24 AC 3,189 ms
8,704 KB
testcase_25 AC 2,172 ms
16,512 KB
testcase_26 AC 2,279 ms
13,568 KB
testcase_27 AC 1,327 ms
18,432 KB
testcase_28 AC 2,354 ms
17,792 KB
testcase_29 AC 2,341 ms
16,896 KB
testcase_30 AC 1,664 ms
19,968 KB
testcase_31 AC 2,380 ms
10,880 KB
testcase_32 AC 1,604 ms
26,368 KB
testcase_33 AC 1,547 ms
27,008 KB
testcase_34 AC 1,659 ms
25,088 KB
testcase_35 AC 1,823 ms
22,528 KB
testcase_36 AC 1,680 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 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