QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#458700 | #8521. Pattern Search II | ucup-team4361# | RE | 201ms | 201120kb | C++14 | 1.5kb | 2024-06-29 18:33:35 | 2024-06-29 18:33:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0' || c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0' && c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
string st[40], s;
vector <int> t[4000100];
inline void build(int l, int r, int id) {
//cout << l << ' ' << r << ' ' << id << endl;
if (l == r) {
t[l].push_back(id);
return;
}
int mid = l + st[id - 1].size() - 1;
build(l, mid, id - 1);
build(mid + 1, r, id - 2);
t[l].push_back(id);
}
int f[40][200010];
int main()
{
st[0] = "b";
st[1] = "a";
int cur = 1;
while (st[cur].size() <= 2000000) {
++cur;
st[cur] = st[cur - 1] + st[cur - 2];
}
int l = 1, r = st[cur].size();
build(l, r, cur);
cin >> s;
for (int i = 0; i < (int)s.size(); i ++) {
if (s[i] == 'a') f[1][i] = 1;
if (s[i] == 'b') f[0][i] = 1;
}
for (int i = 2; i <= cur; i ++)
for (int j = 0; j < (int)s.size(); j ++)
f[i][j] = f[i - 1][j] + f[i - 2][j + f[i - 1][j]];
int n = (int)s.size();
int ans = (int)(st[cur].size());
for (int j = 1; j <= (int)(st[cur].size()) - (int)(s.size()) + 1; j ++) {
int now = j, no = 0;
while (now <= (int)(st[cur].size()) && no < n) {
int L = t[now].size();
for (int i = L - 1; i >= 0; i --) {
int cur_id = t[now][i];
if (no + f[cur_id][no] == n && i != 0) continue;
now += st[cur_id].size();
no += f[cur_id][no];
}
}
if (no != n) break;
ans = min(ans, now - j);
}
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 201ms
memory: 200816kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 140ms
memory: 199620kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 143ms
memory: 200540kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 157ms
memory: 201120kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Runtime Error
input:
bb