QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67739 | #4789. Infinite Pattern Matching | A_zjzj | WA | 3ms | 3436kb | C++14 | 855b | 2022-12-11 18:33:30 | 2022-12-11 18:33:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const int N=60;
int n,a[N];char str[N];ll ans=5e18;
ll calc(int x){int y=__lg(x);ll s=0;for(int i=1;i<=y;i++)s+=((1<<i)-(1<<i-1))*i;s+=(x-(1<<y)+1)*(y+1);return s;}
int trs(int l,int r){int s=0;for(int i=l;i<=r;i++)s=s*2+a[i];return s;}
bool cmp(int l,int r,int x){if(__lg(x)!=r-l)return 0;for(int i=r;i>=l;i--,x>>=1)if(i<=n&&i>=1&&(x&1)!=a[i])return 0;return 1;}
bool chk(int l,int r){
int x=trs(l,r);if(!x)return 0;for(int i=r+1,j=x+1;i<=n;i+=__lg(j++)+1)if(!cmp(i,i+__lg(j),j))return 0;
for(int i=l-1,j=x-1;i>0;i-=__lg(j--)+1)if(j<=0||!cmp(i-__lg(j),i,j))return 0;return 1;
}
int main(){
cin>>str+1;n=strlen(str+1);for(int i=1;i<=n;i++)a[i]=str[i]&1;
for(int i=1;i<=n;i++)if(a[i])for(int j=i;j<=n;j++)if(chk(i,j))
ans=min(ans,calc(trs(i,j))+n-j);cout<<ans;return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3436kb
input:
11
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
011011
output:
42
result:
ok answer is '42'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3352kb
input:
01000110011010110000
output:
5000000000000000000
result:
wrong answer expected '4627720', found '5000000000000000000'