QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246246 | #4666. Delete And Win | Leasier | WA | 0ms | 1604kb | C++98 | 851b | 2023-11-10 17:49:33 | 2023-11-10 17:49:34 |
Judging History
answer
#include <stdio.h>
#include <string.h>
int nxt[100007][27];
char s[100007], t[100007];
inline int min(int a, int b){
return a < b ? a : b;
}
int main(){
int n, m, ni, ans = 0x7fffffff;
scanf("%s", &s[1]);
scanf("%s", &t[1]);
n = strlen(&s[1]);
m = strlen(&t[1]);
ni = n + 1;
for (int i = 1; i <= 26; i++){
nxt[ni][i] = ni;
}
for (int i = n; i >= 1; i--){
for (int j = 1; j <= 26; j++){
nxt[i][j] = nxt[i + 1][j];
}
nxt[i][s[i] - 'a' + 1] = i;
}
for (int i = 0, j = 0; i < m; i++, j++){
if (i > 0){
j = nxt[j][s[i] - 'a' + 1];
if (j > n) break;
}
int ch = t[i + 1] - 'a' + 1, cur_ans = n - j;
for (int k = 1; k < ch; k++){
if (nxt[j + 1][k] <= n) cur_ans = min(cur_ans, nxt[j + 1][k] - j - 1);
}
ans = min(ans, (j - i) + cur_ans);
}
printf("%d", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1604kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'