QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443903#8521. Pattern Search IIucup-team3890#WA 1ms5836kbC++141.2kb2024-06-15 16:48:102024-06-15 16:48:10

Judging History

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

  • [2024-06-15 16:48:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5836kb
  • [2024-06-15 16:48:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int _ = 1.5e5 + 10;
struct node {
	int pos;
	int len;
} f[_][30], g[_][30];
int n, ans = 998244353;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string str;
	cin >> str;
	n = str.length();
	for (int i = 1; i <= n; i++) {
		if (str[i-1] == 'a') {
			f[i][0] = ((node){i + 1, 1});
			g[i][0] = ((node){i - 1, 1});
			f[i][1] = ((node){i, 1});
			g[i][1] = ((node){i, 1});
		} else {
			f[i][0] = ((node){i, 1});
			g[i][0] = ((node){i, 1});
			f[i][1] = ((node){i + 1, 1});
			g[i][1] = ((node){i - 1, 1});
		}
	}
	for (int k = 2; k <= 29; k++) {
		for (int i = 1; i <= n; i++) {
			if (f[i][k-2].pos == 1) {
				f[i][k] = f[i][k-2];
			} else {
				f[i][k] = f[f[i][k-2].pos-1][k-1];
				f[i][k].len += f[i][k-2].len;
			}
			if (g[i][k-1].pos == n) {
				g[i][k] = g[i][k-1];
			} else {
				g[i][k] = g[g[i][k-1].pos+1][k-2];
				g[i][k].len += g[i][k-1].len;
			}
		}
	}
	for (int k = 1; k <= 29; k++) {
		for (int i = 1; i < n; i++) {
			if (f[i][k].pos == 1 && g[i+1][k-1].pos == n) {
				ans = min(ans, f[i][k].len + g[i+1][k-1].len);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5588kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5836kb

input:

a

output:

998244353

result:

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