QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67746 | #4789. Infinite Pattern Matching | A_zjzj | WA | 3ms | 3488kb | C++14 | 1.2kb | 2022-12-11 19:33:20 | 2022-12-11 19:33:22 |
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(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,ll 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){
ll x=trs(l,r),j;if(!x)return 0;j=x+1;for(int i=r+1;i<=n;i+=__lg(j++)+1)if(!cmp(i,i+__lg(j),j))return 0;
j=x-1;for(int i=l-1;i>0;i-=__lg(j--)+1)if(j<=0||!cmp(i-__lg(j),i,j))return 0;return 1;
}
int main(){
ll l=1,r=1ll<<55,mid;
for(;l+1<r;)(calc(mid=(l+r)>>1)<=25282969203030?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);
for(int i=1;i<=n;i++)if(a[i])for(int j=0;j+1<i&&i+j-1<=n;j++)if(comp(1,n-j+1,j)){
ll x=0;for(int k=i;k<=n;k++)x=x*2+a[k];for(int k=j+1;k<i;k++)x=x*2+a[k];ans=min(ans,calc(x)+n-i+1);
}cout<<ans;return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3348kb
input:
11
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3276kb
input:
011011
output:
42
result:
ok answer is '42'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
01000110011010110000
output:
4627720
result:
ok answer is '4627720'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
1011000001101110110111001010001010010101010000101
output:
1617827598069187
result:
ok answer is '1617827598069187'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
101100110110001000010000010111010
output:
4284278055
result:
ok answer is '4284278055'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3456kb
input:
10000111000100011000010101001101001010011111010100000
output:
233619077992339454
result:
ok answer is '233619077992339454'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
0101110001000010010101001000
output:
1743694743
result:
ok answer is '1743694743'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
0000010010000011000110000111101011010111101100
output:
376257416587436
result:
ok answer is '376257416587436'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3416kb
input:
0000001001011101111001
output:
42369600
result:
ok answer is '42369600'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
0011110101101111101000111110111100000000000011
output:
87982575481536
result:
ok answer is '87982575481536'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
10001001111000011010111101011000001000101001101000
output:
1575457563138123
result:
ok answer is '1575457563138123'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3280kb
input:
0100110011001000011110101101111111010000110011
output:
25282969203030
result:
ok answer is '25282969203030'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
0011001100000111010111101001101000000110111100011100
output:
2510541523074945
result:
ok answer is '2510541523074945'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
1110010111100
output:
1590
result:
ok answer is '1590'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
00001101101
output:
9823
result:
ok answer is '9823'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
111000100011100101111000
output:
2530965
result:
ok answer is '2530965'
Test #17:
score: 0
Accepted
time: 3ms
memory: 3280kb
input:
010110100001111011110000010001000110110100111110
output:
1079566051429651
result:
ok answer is '1079566051429651'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3364kb
input:
10111101011110111100100000011011000001001111100001011
output:
13411286390164303
result:
ok answer is '13411286390164303'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
10111100100110010011110100100000101010110000010100
output:
27591604197404888
result:
ok answer is '27591604197404888'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
01000010011100100101100000000001001000
output:
133222173689
result:
ok answer is '133222173689'
Test #21:
score: 0
Accepted
time: 1ms
memory: 3284kb
input:
1111101110010000011011011000101
output:
14492834361
result:
ok answer is '14492834361'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3364kb
input:
110100110001011000101101011
output:
15134266
result:
ok answer is '15134266'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
01101001101011101101101
output:
2960772
result:
ok answer is '2960772'
Test #24:
score: -100
Wrong Answer
time: 2ms
memory: 3344kb
input:
11110101100010000100
output:
3684699
result:
wrong answer expected '2912930', found '3684699'