QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446579#8521. Pattern Search IIucup-team045WA 112ms18736kbC++201.9kb2024-06-17 13:32:572024-06-17 13:32:57

Judging History

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

  • [2024-06-17 13:32:57]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:18736kb
  • [2024-06-17 13:32:57]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
int dp[31][150005];

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int fib[31];
    fib[0] = fib[1] = 1;
    for(int i = 2; i <= 30; i++){
        fib[i] = fib[i - 1] + fib[i - 2];
    }

    string t;
    cin >> t;
    const int n = t.size();
    for(int i = 0; i < n; i++){
        dp[0][i] = (t[i] == 'b');
        dp[1][i] = (t[i] == 'a');
    }
    for(int i = 2; i <= 30; i++){
        for(int j = 0; j < n; j++){
            dp[i][j] = dp[i - 1][j] + dp[i - 2][j + dp[i - 1][j]];
        }
    }

    // 在s[k][x:]位置匹配t[y:]能匹配的长度和需要的代价
    auto dfs = [&](auto &&dfs, int u, int x, int y) -> pair<int, int> {
        if (y == n) 
            return {0, 0};
        if (u == 0){
            if (t[y] == 'b') return {1, 1};
            return {0, 1};
        }
        if (u == 1){
            if (t[y] == 'a') return {1, 1};
            return {0, 1};
        }
        if (x == 0){
            if (y + dp[u][y] < n) return {dp[u][y], fib[u]};
            if (y + dp[u - 1][y] < n){
                auto [a, b] = dfs(dfs, u - 2, 0, y + dp[u - 1][y]);
                return {a + dp[u - 1][y], b + fib[u - 1]};
            }
            return dfs(dfs, u - 1, 0, y);
        }
        if (x < fib[u - 1]){
            auto [a, b] = dfs(dfs, u - 1, x, y);
            if (y + a == n) return {a, b};
            auto [c, d] = dfs(dfs, u - 2, 0, y + a);
            return {a + c, b + d};
        }
        return dfs(dfs, u - 2, x - fib[u - 1], y);
    };

    const int N = 500000;

    int ans = 1e9;
    for(int i = 0; i < N; i++){
        ans = min(ans, dfs(dfs, 30, i, 0).second);
    }
    cout << ans << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 46ms
memory: 3904kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 34ms
memory: 3640kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 42ms
memory: 3664kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 44ms
memory: 3620kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 42ms
memory: 3764kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 44ms
memory: 3672kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 39ms
memory: 3652kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 47ms
memory: 3668kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 50ms
memory: 3772kb

input:

abbbbbbbab

output:

20

result:

ok 1 number(s): "20"

Test #10:

score: 0
Accepted
time: 57ms
memory: 3772kb

input:

abbbbabbbabbbabbabaabbabb

output:

43

result:

ok 1 number(s): "43"

Test #11:

score: 0
Accepted
time: 65ms
memory: 3680kb

input:

bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba

output:

94

result:

ok 1 number(s): "94"

Test #12:

score: 0
Accepted
time: 73ms
memory: 3684kb

input:

ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb

output:

245

result:

ok 1 number(s): "245"

Test #13:

score: 0
Accepted
time: 74ms
memory: 3680kb

input:

aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...

output:

625

result:

ok 1 number(s): "625"

Test #14:

score: 0
Accepted
time: 75ms
memory: 3764kb

input:

aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...

output:

1608

result:

ok 1 number(s): "1608"

Test #15:

score: 0
Accepted
time: 77ms
memory: 4220kb

input:

aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...

output:

3954

result:

ok 1 number(s): "3954"

Test #16:

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

input:

aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...

output:

10033

result:

ok 1 number(s): "10033"

Test #17:

score: 0
Accepted
time: 85ms
memory: 5580kb

input:

aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...

output:

24882

result:

ok 1 number(s): "24882"

Test #18:

score: 0
Accepted
time: 84ms
memory: 8428kb

input:

bbabaaababbabbbbbbababaababaaabababaabbbaabbbabbababbbbbabbbbaaabbbbaaaaabbaaabbbabbbbaabaabbaaaabaababbbababbbbaaaaabaabaababbbbbabbbabbaaabbabbbbaabbabababababababaabbaabbaabbabaaaabaaabbbbbababbbbaaaaabaababbbbabaaaabababaaabaaaabbbbabbbbabaaaaaababbbbabaaabaaaabaaabaabaabaabaaabbabbbbabbababaaab...

output:

62283

result:

ok 1 number(s): "62283"

Test #19:

score: 0
Accepted
time: 94ms
memory: 15296kb

input:

bbbaabaababbaababbbbbbabbbbbbabaabbaaaaabbabbbbbabbabaabbbbaabaaababaaababbaaabababbabbababbbabaabbbabbabbabaabbbbaabaaabbaaabaaabbaaaaabaababbaabaaaabbbbababaababbabaaabababbaabbabbbabbababaaabbbbbabababbaabbbabaaabbaabaababaabbbaabbbaaabbbbabaabbbaaaabbbababaabbaaabaaababbbaabbbaabbbbbabababbababb...

output:

155673

result:

ok 1 number(s): "155673"

Test #20:

score: 0
Accepted
time: 106ms
memory: 12924kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121390

result:

ok 1 number(s): "121390"

Test #21:

score: 0
Accepted
time: 104ms
memory: 12944kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196413

result:

ok 1 number(s): "196413"

Test #22:

score: 0
Accepted
time: 97ms
memory: 12868kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121392

result:

ok 1 number(s): "121392"

Test #23:

score: 0
Accepted
time: 105ms
memory: 12984kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196416

result:

ok 1 number(s): "196416"

Test #24:

score: 0
Accepted
time: 102ms
memory: 12856kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121394

result:

ok 1 number(s): "121394"

Test #25:

score: 0
Accepted
time: 106ms
memory: 13152kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196419

result:

ok 1 number(s): "196419"

Test #26:

score: 0
Accepted
time: 103ms
memory: 18516kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196415

result:

ok 1 number(s): "196415"

Test #27:

score: 0
Accepted
time: 109ms
memory: 18568kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

317806

result:

ok 1 number(s): "317806"

Test #28:

score: 0
Accepted
time: 106ms
memory: 18736kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196417

result:

ok 1 number(s): "196417"

Test #29:

score: 0
Accepted
time: 109ms
memory: 18564kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

317809

result:

ok 1 number(s): "317809"

Test #30:

score: 0
Accepted
time: 112ms
memory: 18488kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196418

result:

ok 1 number(s): "196418"

Test #31:

score: -100
Wrong Answer
time: 110ms
memory: 18556kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

317812

result:

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