QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245948 | #4666. Delete And Win | Nightmare07 | WA | 0ms | 5880kb | C++14 | 1.3kb | 2023-11-10 14:45:22 | 2023-11-10 14:45:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
int lim[N], D[N], log_2[N];
char a[N], b[N], st[N][20];
char ST(int l, int r) {
int k = log_2[r - l + 1];
return max(st[l][k], st[r - (1 << k) + 1][k]);
}
int main() {
scanf("%s%s", a + 1, b + 1);
n = strlen(a + 1), m = strlen(b + 1);
for (int i = 2; i <= n; i ++) log_2[i] = log_2[i / 2] + 1;
for (int i = 1; i <= n; i ++) st[i][0] = a[i];
for (int j = 1; (1 << j) <= n; j ++) {
for (int i = 1; i + (1 << j) - 1 <= n; i ++) {
st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
}
}
lim[0] = 0;
for (int i = 1; i <= n; i ++) {
if (lim[i - 1] == -1) lim[i] = -1;
else {
lim[i] = lim[i - 1];
while (lim[i] < m && a[i] != b[lim[i] + 1]) lim[i] ++;
lim[i] ++;
if (lim[i] > m) lim[i] = -1;
}
}
D[0] = 0;
for (int i = 1, j = 0; i <= m; i ++) {
if (j < n && i == lim[j + 1]) j ++;
D[i] = j;
}
int ans = 2e9;
for (int i = 1; i <= m; i ++) {
int l = 1, r = min(n, D[i - 1] + 1);
if (ST(l, r) <= b[i]) continue;
while (l < r) {
int mid = l + r + 1 >> 1;
if (ST(mid, min(n, D[i - 1] + 1)) > b[i]) l = mid;
else r = mid - 1;
}
ans = min(ans, i - l);
}
if (D[m] < n) ans = min(ans, m - D[m]);
else ans = min(ans, m - D[m] + 1);
printf("%d", ans);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5880kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'