QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700499 | #4666. Delete And Win | hcywoi | WA | 0ms | 3864kb | C++23 | 956b | 2024-11-02 13:06:13 | 2024-11-02 13:06:13 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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