QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#451449#8521. Pattern Search IIHKOI0#WA 0ms3856kbC++201.2kb2024-06-23 13:32:432024-06-23 13:32:43

Judging History

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

  • [2024-06-23 13:32:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-06-23 13:32:43]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

void solve() {
    int c0 = 1, c1 = 1;
    string s; cin >> s;
    int ord = s.size();
    int ans = 0;
    while (s.size() >= 3) {
        string t;
        if (s.front() != 'a') t.push_back('a');
        for (int i = 0; i < s.size(); i++) {
            if (i > 0 && s[i] == 'b' && s[i - 1] == 'b') {
                t.push_back('a');
                ans += c0;
            }
            t.push_back(s[i]);
        }

        string ns;
        for (int i = 0; i < t.size(); i++) {
            if (i + 1 < t.size() && t[i + 1] == 'b') {
                ns.push_back('a'); i++;
            } else {
                ns.push_back('b');
            }
        }
        s = ns;
        int c2 = c0 + c1;
        c0 = c1; c1 = c2;
    }
    if (s == "bb") {
        ans += c0;
    }
    cout << ord + ans << '\n';
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

bbba

output:

8

result:

wrong answer 1st numbers differ - expected: '7', found: '8'