QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246246#4666. Delete And WinLeasierWA 0ms1604kbC++98851b2023-11-10 17:49:332023-11-10 17:49:34

Judging History

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

  • [2023-11-10 17:49:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1604kb
  • [2023-11-10 17:49:33]
  • 提交

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'