QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#522867 | #8521. Pattern Search II | ophQ | WA | 16ms | 8416kb | C++14 | 865b | 2024-08-17 16:13:33 | 2024-08-17 16:13:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
int n,ans=INT_MAX;
struct node{
int len;
pair<int,int>f[N],g[N];
}a,b;
node merge(node&x,node&y){
node z;
z.len=x.len+y.len;
for(int i=1;i<=n;i++){
z.f[i]=x.f[i].first==n+1?x.f[i]:make_pair(y.f[x.f[i].first].first,x.len+y.f[x.f[i].first].second),
z.g[i]=y.g[i].first== 0 ?y.g[i]:make_pair(x.g[y.g[i].first].first,y.len+x.g[y.g[i].first].second);
if(x.g[i].first==0&&y.f[i+1].first==n+1)ans=min(ans,x.g[i].second+y.f[i+1].second);
}
return z;
}
string s;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>s,n=s.size();
for(int i=1;i<=n;i++)if(s[i-1]=='a')b.f[i]={i+1,1},b.g[i]={i-1,1},a.f[i]=a.g[i]={i,0};
else a.f[i]={i+1,1},a.g[i]={i-1,1},b.f[i]=b.g[i]={i,0};
a.len=b.len=1;
for(int i=1;i<=30;i++)swap(a,b),b=merge(a,b);
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 8416kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 8352kb
input:
a
output:
2147483647
result:
wrong answer 1st numbers differ - expected: '1', found: '2147483647'