QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#451448 | #8521. Pattern Search II | HKOI0# | WA | 0ms | 3532kb | C++20 | 1.1kb | 2024-06-23 13:31:19 | 2024-06-23 13:31:21 |
Judging History
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;
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3500kb
input:
bb
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'