QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67742#4789. Infinite Pattern MatchingA_zjzjWA 2ms3416kbC++141.3kb2022-12-11 19:18:412022-12-11 19:18:43

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-11 19:18:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3416kb
  • [2022-12-11 19:18:41]
  • 提交

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(ll x){int y=__lg(x);ll s=0;for(int i=1;i<=y;i++)s+=((1ll<<i)-(1ll<<i-1))*i;s+=(x-(1ll<<y)+1)*(y+1);return s;}
ll trs(int l,int r){ll 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 comp(int x,int y,int len){for(int i=0;i<len;i++)if(a[i+x]!=a[i+y])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;
}
ll get(){
	ll ans;int t=0,st=-1,ed=-1;for(int i=1;i*2<n;i++)if(comp(1,n-i+1,i))t=i;
	for(int i=1;i<=n-t;i++)if(a[i])ed=i;for(int i=n-t;i>=1;i--)if(a[i])st=i;
	ans=1;for(int i=n-t-ed;i;i--)ans*=2;for(int i=1;i<ed;i++)ans=ans*2+a[i];ans=calc(ans)+n-ed+1;return ans;
}
int main(){
	ll l=1,r=1ll<<55,mid;
	for(;l+1<r;)(calc(mid=(l+r)>>1)<=1617827598069187?l:r)=mid;
	cerr<<l<<' '<<calc(l)<<endl;
	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);
	ans=min(ans,get());cout<<ans;return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3356kb

input:

11

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3356kb

input:

011011

output:

42

result:

ok answer is '42'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3284kb

input:

01000110011010110000

output:

4627720

result:

ok answer is '4627720'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3368kb

input:

1011000001101110110111001010001010010101010000101

output:

1617827598069187

result:

ok answer is '1617827598069187'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3284kb

input:

101100110110001000010000010111010

output:

4284278055

result:

ok answer is '4284278055'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

10000111000100011000010101001101001010011111010100000

output:

233619077992339454

result:

ok answer is '233619077992339454'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3356kb

input:

0101110001000010010101001000

output:

1840971516

result:

wrong answer expected '1743694743', found '1840971516'