QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#700499#4666. Delete And WinhcywoiWA 0ms3864kbC++23956b2024-11-02 13:06:132024-11-02 13:06:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 13:06:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3864kb
  • [2024-11-02 13:06:13]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
  std::string S, T;
  std::cin >> S >> T;

  int N = S.size();
  int M = T.size();

  std::vector<std::vector<int>> vec(26);
  for (int i = 0; i < N; i++) {
    vec[S[i] - 'a'].push_back(i);
  }

  int t = 0;
  int ans = N;
  for (int i = 0; i < M; i++) {
    ans = std::min(ans, N - i);
    int u = T[i] - 'a';
    for (int j = 0; j < u; j++) {
      int k = lower_bound(vec[j].begin(), vec[j].end(), t) - vec[j].begin();
      if (k < vec[j].size()) {
        ans = std::min(ans, vec[j][k] - i);
      }
    }
    int k = lower_bound(vec[u].begin(), vec[u].end(), t) - vec[u].begin();
    if (k == vec[u].size()) {
      break;
    }
    t = vec[u][k] + 1;
  }
  std::cout << ans << "\n";
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int t;
  std::cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3864kb

input:

pqsrpspqz
pqrpqz

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements