QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245921#4666. Delete And WinSham_DevourWA 1ms3832kbC++14749b2023-11-10 14:39:342023-11-10 14:39:36

Judging History

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

  • [2023-11-10 14:39:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2023-11-10 14:39:34]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1e5 + 5, S = 26;

char s[N], t[N];
int ns, nt, tot, ans, pos[N], lst[S];

int main() {
	scanf("%s %s", s + 1, t + 1), ns = strlen(s + 1), nt = strlen(t + 1);
	ans = nt;
	for (int i = 1, j = 1; i < ns; i++) {
		while (j <= nt && s[i] != t[j]) j++;
		if (j <= nt) pos[++tot] = j++;
		else break;
	}
	for (int i = tot, j = nt; i >= 0; i--) {
		if (pos[i] == nt) {ans = min(ans, pos[i] - i); continue;}
		while (j > pos[i]) lst[t[j] - 'a'] = j, j--;
		int p = 1e9;
		for (int k = 0; k < s[i + 1] - 'a'; k++)
			if (lst[k]) p = min(p, lst[k]);
		if (p == 1e9) continue;
		ans = min(ans, p - i - 1);
	}
	printf("%d", ans);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3832kb

input:

pqsrpspqz
pqrpqz

output:

0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'