QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468663#8521. Pattern Search IIucup-team3519#WA 0ms3848kbC++201.7kb2024-07-08 22:24:072024-07-08 22:24:09

Judging History

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

  • [2024-07-08 22:24:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2024-07-08 22:24:07]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = int64_t;

int main() {
    std::string s;
    std::cin >> s;

    std::vector<int> a;
    for (char c : s) {
        if (c == 'a') {
            a.push_back(1);
        } else {
            a.push_back(0);
        }
    }

    std::vector<i64> f{1, 1};
    while (true) {
        i64 nf = f[f.size() - 1] + f[f.size() - 2];
        if (nf < 1e12) {
            f.push_back(nf);
        } else {
            break;
        }
    }
    // for (int i : a) {
    //     std::cout << i << ' ';
    // }
    // std::cout << '\n';

    i64 ans = s.size();
    while (a.size() > 1) {
        int min_v = *std::min_element(a.begin(), a.end());
        std::vector<int> na;
        for (int i = 0; i < a.size(); ++i) {
            int x = a[i];
            if (x == min_v) {
                if (na.empty()) {
                    na.push_back(x + 2);
                } else if (na.back() == x + 1) {
                    na.back() = x + 2;
                } else {
                    if (x == 0) {
                        na.push_back(2);
                        ans += 1;
                    } else {
                        if (i == a.size() - 1) {
                            na.push_back(x + 1);
                        } else {
                            na.push_back(x + 1);
                            ans += f[x - 1];
                        }
                    }
                }
            } else {
                na.push_back(x);
            }
        }
        a = std::move(na);
        // for (int i : a) {
        //     std::cout << i << ' ';
        // }
        // std::cout << '\n';
    }

    std::cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 3492kb

input:

abbbbbbbab

output:

22

result:

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