QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104746#4789. Infinite Pattern MatchingDeterminantWA 3ms3804kbC++141.2kb2023-05-11 20:40:332023-05-11 20:40:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-11 20:40:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3804kb
  • [2023-05-11 20:40:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;typedef long long ll;
char a[56];ll m,t1;int n,t2;
ll get(int l,int r,ll x){return (x>>l)&((1ll<<(r-l+1))-1);}
int main(){
	scanf("%s",a);n=strlen(a);for(int i=0;i<n;++i)m|=(1ll<<i)*(a[n-1-i]-48);
	t1=(a[0]=='0'?m+(1ll<<n):m);
	for(int l=0;l<n;++l)for(int r=l;r<n;++r)if(get(r,r,m)){
		ll x=get(l,r,m),u=x;int lt=r+1,rt=l-1,fl=1;
		while(1){
			u--;if(u<=0){if(lt<n)fl=0;break;}
			if(lt+__lg(u)<n){if(get(lt,lt+__lg(u),m)!=u){fl=0;break;}}
			else{if(get(lt,n-1,m)!=get(0,n-1-lt,u))fl=0;break;}lt+=__lg(u)+1;
		}
		u=x;while(1){
			u++;if(rt-__lg(u)>=0){if(get(rt-__lg(u),rt,m)!=u){fl=0;break;}}
			else{if(get(0,rt,m)!=get(__lg(u)-rt,__lg(u),u))fl=0;break;}
			rt-=__lg(u)+1;
		}
		if(fl&&(u<t1-1||(u==t1-1&&rt<t2)))t1=u-1,t2=rt+1;
	}
	for(int l=1;l<n;++l)if(get(l-1,l-1,m)){
		ll lt=get(0,l-1,m)-1,rt=lt,nd=get(l,n-1,m),w;
		while(1){
			if(rt-lt+1>=(1ll<<l))break;
			ll lx=lt&((1ll<<l)-1),rx=rt&((1ll<<l)-1);
			if((lx<=nd&&nd<=rx)||(lx>rx&&(nd<=rx||nd>=lx)))break;
			lt=2*lt+1;rt=2*rt+2;
		}
		w=nd-(lt&((1ll<<l)-1));if(w<0)w+=(1ll<<l);w+=lt;
		if(w<t1||(w==t1&&n-l<t2))t1=w,t2=n-l;
	}
	int q=__lg(t1);printf("%lld\n",(1ll<<q)*(q-1)+1+1ll*(q+1)*(t1-(1ll<<q)+1)+t2);
}

詳細信息

Test #1:

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

input:

11

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 3ms
memory: 3576kb

input:

011011

output:

42

result:

ok answer is '42'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3572kb

input:

01000110011010110000

output:

40161

result:

wrong answer expected '4627720', found '40161'