QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245933#4669. Genetic ModificationsNightmare07WA 1ms6004kbC++141.3kb2023-11-10 14:41:152023-11-10 14:41:19

Judging History

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

  • [2023-11-10 14:41:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6004kb
  • [2023-11-10 14:41:15]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

BBAAABBAAABAAA
BAAB

output:

0

result:

wrong output format Unexpected end of file - int32 expected