QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#496259#8521. Pattern Search IIucup-team1766WA 109ms55620kbC++171.9kb2024-07-28 05:21:372024-07-28 05:21:37

Judging History

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

  • [2024-07-28 05:21:37]
  • 评测
  • 测评结果:WA
  • 用时:109ms
  • 内存:55620kb
  • [2024-07-28 05:21:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int FIB = 30;
int fibs[FIB];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    fibs[0] = 1;
    fibs[1] = 1;
    for (int i = 2; i < FIB; i++) {
        fibs[i] = fibs[i - 1] + fibs[i - 2];
    }
    
    vector<vector<int>> starts(fibs[FIB - 1]);
    starts[0].push_back(1);
    starts[0].push_back(2);
    starts[1].push_back(0);
    for (int i = 3; i < FIB; i++) {
        starts[0].push_back(i);
        for (int j = 0; j < fibs[i - 2]; j++) {
            for (int k : starts[j]) {
                starts[fibs[i - 1] + j].push_back(k);
            }
        }
        starts[fibs[i - 1]].push_back(i - 2);
    }
    for (int i = 0; i < FIB - 1; i++) {
        sort(starts[i].begin(), starts[i].end());
    }

    string s;
    cin >> s;
    int n = s.length();

    // dp[i][j] = max subsequence match of s[i...] to S_j
    vector<vector<int>> dp(n + 1, vector<int>(FIB));
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            dp[i][1] = 1;
        } else {
            dp[i][0] = 1;
        }
    }
    for (int j = 2; j < FIB; j++) {
        for (int i = 0; i < n; i++) {
            dp[i][j] = max(dp[i][j], dp[i][j - 1] + dp[i + dp[i][j - 1]][j - 2]);
        }
    }

    int res = INT_MAX;
    for (int i = 0; i < fibs[FIB - 2]; i++) {
        int cur = i;
        int ind = 0;
        while (true) {
            bool moved = false;
            for (int j = starts[cur].size() - 1; j >= 0; j--) {
                if (ind + dp[ind][starts[cur][j]] < n) {
                    ind += dp[ind][starts[cur][j]];
                    cur += fibs[starts[cur][j]];
                    moved = true;
                    break;
                }
            }
            if (!moved) {
                break;
            }
        }
        res = min(res, cur - i + 1);
    }
    cout << res << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 57ms
memory: 54972kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 46ms
memory: 55064kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 53ms
memory: 55072kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 60ms
memory: 54948kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 61ms
memory: 55000kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 59ms
memory: 54816kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 67ms
memory: 55160kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 60ms
memory: 55148kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

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

input:

abbbbbbbab

output:

20

result:

ok 1 number(s): "20"

Test #10:

score: 0
Accepted
time: 71ms
memory: 55024kb

input:

abbbbabbbabbbabbabaabbabb

output:

43

result:

ok 1 number(s): "43"

Test #11:

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

input:

bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba

output:

94

result:

ok 1 number(s): "94"

Test #12:

score: 0
Accepted
time: 95ms
memory: 55272kb

input:

ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb

output:

245

result:

ok 1 number(s): "245"

Test #13:

score: 0
Accepted
time: 95ms
memory: 54908kb

input:

aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...

output:

625

result:

ok 1 number(s): "625"

Test #14:

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

input:

aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...

output:

1608

result:

ok 1 number(s): "1608"

Test #15:

score: -100
Wrong Answer
time: 108ms
memory: 55620kb

input:

aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...

output:

3951

result:

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