QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245937 | #4666. Delete And Win | pbk5418 | WA | 1ms | 3592kb | C++14 | 654b | 2023-11-10 14:41:52 | 2023-11-10 14:41:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int sn,tn,ans,now,f[N][26];
char s[N],t[N];
int main() {
scanf("%s%s",s + 1,t + 1);
sn = strlen(s + 1),tn = strlen(t + 1);
for (int i = tn - 1; i >= 0; i --) {
for (int j = 25; j >= 0; j --) f[i][j] = f[i + 1][j];
f[i][t[i + 1] - 'a'] = i + 1;
}
int sum = 0;
ans = tn;
for (int i = 0; i < sn; i ++) {
for (int j = 0; j < s[i + 1] - 'a'; j ++) if (f[now][j]) ans = min(ans,sum + f[now][j] - now - 1);
if (!f[now][s[i + 1] - 'a']) break;
sum += f[now][s[i + 1] - 'a'] - now - 1;
now = f[now][s[i + 1] - 'a'];
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3592kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'