QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#445790#8521. Pattern Search IIMine_KingTL 2616ms31296kbC++141.4kb2024-06-16 14:03:312024-06-16 14:03:31

Judging History

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

  • [2024-06-16 14:03:31]
  • 评测
  • 测评结果:TL
  • 用时:2616ms
  • 内存:31296kb
  • [2024-06-16 14:03:31]
  • 提交

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 <= 15 * n; 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;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 28280kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 10ms
memory: 28628kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 10ms
memory: 29168kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 10ms
memory: 28824kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 4ms
memory: 29116kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 13ms
memory: 29092kb

input:

abbbbbbbab

output:

20

result:

ok 1 number(s): "20"

Test #10:

score: 0
Accepted
time: 13ms
memory: 29048kb

input:

abbbbabbbabbbabbabaabbabb

output:

43

result:

ok 1 number(s): "43"

Test #11:

score: 0
Accepted
time: 7ms
memory: 29176kb

input:

bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba

output:

94

result:

ok 1 number(s): "94"

Test #12:

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

input:

ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb

output:

245

result:

ok 1 number(s): "245"

Test #13:

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

input:

aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...

output:

625

result:

ok 1 number(s): "625"

Test #14:

score: 0
Accepted
time: 81ms
memory: 28716kb

input:

aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...

output:

1608

result:

ok 1 number(s): "1608"

Test #15:

score: 0
Accepted
time: 429ms
memory: 29188kb

input:

aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...

output:

3954

result:

ok 1 number(s): "3954"

Test #16:

score: 0
Accepted
time: 2616ms
memory: 31296kb

input:

aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...

output:

10033

result:

ok 1 number(s): "10033"

Test #17:

score: -100
Time Limit Exceeded

input:

aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...

output:


result: