QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#510534 | #8521. Pattern Search II | UNos_maricones | WA | 0ms | 3624kb | C++20 | 2.7kb | 2024-08-09 08:57:50 | 2024-08-09 08:57:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef long double lf;
typedef pair <ll,ll> pii;
const ll N = 3e5 + 5;
const ll S = 2010;
const ll LOG_N = 18;
const ll oo = 1e16+7;
const ll mod = 2e9 + 7;
int main () {
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
string s; cin >> s;
int n = s.size();
vector <vector<ll>> mx(n + 1, vector<ll>(50));
vector <vector<ll>> mn(n + 1, vector<ll>(50));
vector <vector<ll>> sz_l (n + 1, vector<ll>(50));
vector <vector<ll>> sz_r (n + 1, vector<ll>(50));
vector <ll> fib(50);
fib[0] = fib[1] = 1;
for (int i = 2; i < 50; ++i) fib[i] = fib[i - 1] + fib[i - 2];
for (int w = 0; w < 50; ++w)
mx[n][w] = n, mn[0][w] = 0;
for (int w = 0; w < 7; ++w) {
for (int i = 0; i < n; ++i) {
if (w == 0) {
mx[i][w] = (s[i] == 'b' ? i + 1 : i);
mn[i + 1][w] = (s[i] == 'b' ? i : i + 1);
}
else if (w == 1) {
mx[i][w] = (s[i] == 'a' ? i + 1 : i);
mn[i + 1][w] = (s[i] == 'a' ? i : i + 1);
}
else {
mx[i][w] = mx[mx[i][w - 1]][w - 2];
mn[i + 1][w] = mn[mn[i + 1][w - 2]][w - 1];
}
}
}
for (int w = 0; w < 7; ++w) {
for (int i = 0; i < n; ++i) {
if (w == 0) {
if (s[i] == 'b' && i == n - 1) sz_l[i][w] = 1;
else sz_l[i][w] = oo;
if (s[i] == 'b' && i == 0) sz_r[i + 1][w] = 1;
else sz_r[i + 1][w] = oo;
}
else if (w == 1) {
if (s[i] == 'a' && i == n - 1) sz_l[i][w] = 1;
else sz_l[i][w] = oo;
if (s[i] == 'a' && i == 0) sz_r[i + 1][w] = 1;
else sz_r[i + 1][w] = oo;
}
else {
if (mx[i][w - 1] == n) sz_l[i][w] = sz_l[i][w - 1];
else sz_l[i][w] = fib[w - 1] + sz_l[mx[i][w - 1]][w - 2];
if (mn[i + 1][w - 2] == 0) sz_r[i + 1][w] = sz_r[i + 1][w - 2];
else sz_r[i + 1][w] = fib[w - 2] + sz_r[mn[i + 1][w - 2]][w - 1];
}
}
}
for (int w = 0; w < 50; ++w) {
if (mx[0][w] == n) {
if (w == 0 || w == 1) {
cout << 1 << '\n';
break;
}
ll ans = oo;
for (int j = 1; j < n; ++j) {
if (mx[0][w - 1] >= j && mx[j][w - 2] >= n) {
ans = min(ans, sz_l[j][w - 2] + sz_r[j][w - 1]);
}
}
cout << ans << '\n';
break;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
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: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
aa
output:
3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'