QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#445792#8521. Pattern Search IIMine_KingTL 3264ms29252kbC++141.4kb2024-06-16 14:05:292024-06-16 14:05:30

Judging History

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

  • [2024-06-16 14:05:30]
  • 评测
  • 测评结果:TL
  • 用时:3264ms
  • 内存:29252kb
  • [2024-06-16 14:05:29]
  • 提交

answer

// 長い夜の終わりを信じながら
// Think twice, code once.
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;

int fib[35], ans = 0x3f3f3f3f, mx[3000005], id[3000005];
int n, dp[150005][35];
string s;

int main() {
	fib[0] = fib[1] = 1;
	for (int i = 2; i <= 32; i++) fib[i] = fib[i - 1] + fib[i - 2];
	mx[3] = 2;
	id[1] = 1, id[2] = 0, id[3] = 1;
	for (int i = 4; i <= 3000000; i++) {
		mx[i] = mx[i - 1] + (fib[mx[i - 1] + 1] < i);
		id[i] = id[i - fib[mx[i]]];
	}
	eprintf("%d\n", fib[31]);
	cin >> s;
	n = s.length();
	s = " " + s;
	for (int i = 1; i <= n; i++)
		if (s[i] == 'b') dp[i][0] = 1, dp[i][1] = 0;
		else dp[i][0] = 0, dp[i][1] = 1;
	for (int j = 2; j <= 30; j++)
		for (int i = 1; i <= n; i++) dp[i][j] = dp[i][j - 1] + dp[i + dp[i][j - 1]][j - 2];
	for (int i = 1; i <= 2178309; i++)
		if ((id[i] >= 1 ? 'a' : 'b') == s[1]) {
			// eprintf("%d\n", i);
			int now = i, p = 1;
			while (p <= n) {
				int id = ::id[now];
				while (id > 1 && p + dp[p][id] == n + 1) id--;
				// eprintf("%d %d %d\n", now, id, p);
				p += dp[p][id];
				now += fib[id];
			}
			ans = min(ans, now - i);
		}
	printf("%d\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 29208kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 15ms
memory: 28284kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 15ms
memory: 28936kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 14ms
memory: 27208kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 12ms
memory: 27480kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 21ms
memory: 28308kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 11ms
memory: 27932kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 27ms
memory: 28924kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 92ms
memory: 28792kb

input:

abbbbbbbab

output:

20

result:

ok 1 number(s): "20"

Test #10:

score: 0
Accepted
time: 221ms
memory: 27640kb

input:

abbbbabbbabbbabbabaabbabb

output:

43

result:

ok 1 number(s): "43"

Test #11:

score: 0
Accepted
time: 316ms
memory: 28588kb

input:

bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba

output:

94

result:

ok 1 number(s): "94"

Test #12:

score: 0
Accepted
time: 1315ms
memory: 27356kb

input:

ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb

output:

245

result:

ok 1 number(s): "245"

Test #13:

score: 0
Accepted
time: 3264ms
memory: 29252kb

input:

aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...

output:

625

result:

ok 1 number(s): "625"

Test #14:

score: -100
Time Limit Exceeded

input:

aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...

output:


result: