QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67748 | #4789. Infinite Pattern Matching | A_zjzj | WA | 2ms | 3532kb | C++14 | 1.4kb | 2022-12-11 19:43:12 | 2022-12-11 19:43:16 |
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)<=2912930?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];bool t=1;
for(int k=j+1;k<i;k++)x=x*2+a[k],t&=a[k];if(!t)ans=min(ans,calc(x)+n-i+1);
}int cnt=0;for(int i=n;i>=1&&!a[i];i--)cnt++;for(int i=1;i<n&&a[i];i++)if(i>cnt&&a[i+1]){
ll x=0;for(int j=i+1;j<=n-cnt-1;j++)x=x*2+a[j];x*=2;for(int j=1;j<=i;j++)x=x*2+1;ans=min(ans,calc(x)+n-i);
}cout<<ans;return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3364kb
input:
11
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3340kb
input:
011011
output:
42
result:
ok answer is '42'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
01000110011010110000
output:
4627720
result:
ok answer is '4627720'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
1011000001101110110111001010001010010101010000101
output:
1617827598069187
result:
ok answer is '1617827598069187'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
101100110110001000010000010111010
output:
4284278055
result:
ok answer is '4284278055'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
10000111000100011000010101001101001010011111010100000
output:
233619077992339454
result:
ok answer is '233619077992339454'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3364kb
input:
0101110001000010010101001000
output:
1743694743
result:
ok answer is '1743694743'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
0000010010000011000110000111101011010111101100
output:
376257416587436
result:
ok answer is '376257416587436'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
0000001001011101111001
output:
42369600
result:
ok answer is '42369600'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
0011110101101111101000111110111100000000000011
output:
87982575481536
result:
ok answer is '87982575481536'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
10001001111000011010111101011000001000101001101000
output:
1575457563138123
result:
ok answer is '1575457563138123'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
0100110011001000011110101101111111010000110011
output:
25282969203030
result:
ok answer is '25282969203030'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
0011001100000111010111101001101000000110111100011100
output:
2510541523074945
result:
ok answer is '2510541523074945'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
1110010111100
output:
1590
result:
ok answer is '1590'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3352kb
input:
00001101101
output:
9823
result:
ok answer is '9823'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
111000100011100101111000
output:
2530965
result:
ok answer is '2530965'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3288kb
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: 3352kb
input:
10111100100110010011110100100000101010110000010100
output:
27591604197404888
result:
ok answer is '27591604197404888'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
01000010011100100101100000000001001000
output:
133222173689
result:
ok answer is '133222173689'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
1111101110010000011011011000101
output:
14492834361
result:
ok answer is '14492834361'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
110100110001011000101101011
output:
15134266
result:
ok answer is '15134266'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
01101001101011101101101
output:
2960772
result:
ok answer is '2960772'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
11110101100010000100
output:
2912930
result:
ok answer is '2912930'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
0110101111110000110110010001
output:
851548114
result:
ok answer is '851548114'
Test #26:
score: 0
Accepted
time: 2ms
memory: 3424kb
input:
101001001101
output:
2277
result:
ok answer is '2277'
Test #27:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
11001110001000010110001100001111011111000
output:
25745895511785
result:
ok answer is '25745895511785'
Test #28:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
110110111011011100001001010011011000010011
output:
21689826093692
result:
ok answer is '21689826093692'
Test #29:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
10100111010111000101
output:
1074100
result:
ok answer is '1074100'
Test #30:
score: 0
Accepted
time: 2ms
memory: 3368kb
input:
00000010000011110111110101111111100
output:
134284782980
result:
ok answer is '134284782980'
Test #31:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
0110100100100111101000010
output:
115678982
result:
ok answer is '115678982'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
10110110010101100001111010110110
output:
196625955
result:
ok answer is '196625955'
Test #33:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
10100011010
output:
451
result:
ok answer is '451'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
1111000100
output:
24
result:
ok answer is '24'
Test #35:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
00001111101010001100100011101111001000000110110001100
output:
55928791305821883
result:
ok answer is '55928791305821883'
Test #36:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
00111110101001111011011011010111
output:
1604391490
result:
ok answer is '1604391490'
Test #37:
score: 0
Accepted
time: 2ms
memory: 3424kb
input:
0100111110110100110110000000101111001
output:
81289151237
result:
ok answer is '81289151237'
Test #38:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
1101101010011110010
output:
676819
result:
ok answer is '676819'
Test #39:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
000010001100010110011110000011101001110000110101101110
output:
236494750473271977
result:
ok answer is '236494750473271977'
Test #40:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
001011011110
output:
11243
result:
ok answer is '11243'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
1101110111011101
output:
17479
result:
ok answer is '17479'
Test #42:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
11011001110000101101
output:
482124
result:
ok answer is '482124'
Test #43:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
0110100111110001101101
output:
1101916
result:
ok answer is '1101916'
Test #44:
score: 0
Accepted
time: 2ms
memory: 3524kb
input:
111110000000000100111010000110110011101111011001
output:
1350318850097835
result:
ok answer is '1350318850097835'
Test #45:
score: 0
Accepted
time: 1ms
memory: 3348kb
input:
01101111111001000000
output:
4524495
result:
ok answer is '4524495'
Test #46:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
1010111100010001111001010111010100000001011000000000011
output:
342091330255876309
result:
ok answer is '342091330255876309'
Test #47:
score: 0
Accepted
time: 2ms
memory: 3492kb
input:
0011101100010111011001100001011111010000101010011000110
output:
488508015662352479
result:
ok answer is '488508015662352479'
Test #48:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
1111100101100011000011100000010010010001011000011100010
output:
552697917399006612
result:
ok answer is '552697917399006612'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
0101010110111111100011011011011100111111001101010111111
output:
310794647125722338
result:
ok answer is '310794647125722338'
Test #50:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
1110111011011100010110111001011110000111111001001110000
output:
340531374829154662
result:
ok answer is '340531374829154662'
Test #51:
score: 0
Accepted
time: 1ms
memory: 3268kb
input:
1101011001111000101001010100100101110110111001101010010
output:
153703145787415367
result:
ok answer is '153703145787415367'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
0110110000001011101001011111111100000000110001001000001
output:
230399308022984473
result:
ok answer is '230399308022984473'
Test #53:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
0001010000110111000101110101111100100101110000010010110
output:
477289782382961687
result:
ok answer is '477289782382961687'
Test #54:
score: 0
Accepted
time: 1ms
memory: 3320kb
input:
1100110100000010000110010100011001011110100110001101001
output:
32742663819349731
result:
ok answer is '32742663819349731'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3268kb
input:
1001100111101001010011110100010100100111011110110010001
output:
504927465900691460
result:
ok answer is '504927465900691460'
Test #56:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
0001101010101110101100000111001010101000011011101100111
output:
45814239190627479
result:
ok answer is '45814239190627479'
Test #57:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
0101100001010101101100101100001110110111011101110010010
output:
119389948060291287
result:
ok answer is '119389948060291287'
Test #58:
score: 0
Accepted
time: 1ms
memory: 3348kb
input:
0111101001110011100101011011001001111001100001011010101
output:
209380660973652414
result:
ok answer is '209380660973652414'
Test #59:
score: 0
Accepted
time: 2ms
memory: 3364kb
input:
0011101111010111111100100000000010001000010101100011001
output:
112711787535267718
result:
ok answer is '112711787535267718'
Test #60:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
1000000010000011101010101111101101010100111011111100100
output:
113060494433323880
result:
ok answer is '113060494433323880'
Test #61:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
0100000100100110110011001001011101100110111001001110111
output:
233978371494861166
result:
ok answer is '233978371494861166'
Test #62:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
1110110101110010100100001011011001000011010110001100011
output:
195740199453835543
result:
ok answer is '195740199453835543'
Test #63:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
1000001111001100101010100001101011111001110110111000001
output:
6674447445449032
result:
ok answer is '6674447445449032'
Test #64:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
1111010010010010101011110001000001000011000111111011110
output:
27482870241374655
result:
ok answer is '27482870241374655'
Test #65:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
0011111100101111011111010111100110110010001011100110000
output:
244411899637632648
result:
ok answer is '244411899637632648'
Test #66:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
1011100111111100011001011100100000111001011001111001111
output:
101798322115572895
result:
ok answer is '101798322115572895'
Test #67:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
0101010000100001111011011000000010101101101001011000100
output:
470951868793563220
result:
ok answer is '470951868793563220'
Test #68:
score: 0
Accepted
time: 2ms
memory: 3368kb
input:
0101001000000011101001011110011101110010011001001001010
output:
27222152140268876
result:
ok answer is '27222152140268876'
Test #69:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
0100010001110100101000101010100011100101110111001110011
output:
246300960826437380
result:
ok answer is '246300960826437380'
Test #70:
score: 0
Accepted
time: 2ms
memory: 3368kb
input:
1101100011110111001110111111110011110011110010000100000
output:
658109745667120887
result:
ok answer is '658109745667120887'
Test #71:
score: 0
Accepted
time: 0ms
memory: 3356kb
input:
1000010101011000010001110110011010000011110001010101011
output:
482703240276676562
result:
ok answer is '482703240276676562'
Test #72:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
0011111001010011011101101010100001100001110010111111111
output:
1002075782371010585
result:
ok answer is '1002075782371010585'
Test #73:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
1110001101001000110011111001011101111100000000100011101
output:
361278349234609565
result:
ok answer is '361278349234609565'
Test #74:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
0100011100001000011111110010000101000001111001101010100
output:
56874688376383344
result:
ok answer is '56874688376383344'
Test #75:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
1110010111101100111111000001111111111010100001101011110
output:
56962299438155523
result:
ok answer is '56962299438155523'
Test #76:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
1010111000100101011000011111001111011101011111001000001
output:
478714042587854950
result:
ok answer is '478714042587854950'
Test #77:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
1111111000001000110011101101111110010101111110001001101
output:
461043595412184597
result:
ok answer is '461043595412184597'
Test #78:
score: 0
Accepted
time: 2ms
memory: 3424kb
input:
1110110101101011010110010001001100111011011101110000110
output:
95919384048798599
result:
ok answer is '95919384048798599'
Test #79:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
1010110010101101000010001101100101000011001001110111010
output:
57153857862611838
result:
ok answer is '57153857862611838'
Test #80:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
0001001010011011100000001111010000110001110100001100000
output:
113462598761170904
result:
ok answer is '113462598761170904'
Test #81:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
0001001001000000101111001001101111111011101011110110010
output:
473973570716799997
result:
ok answer is '473973570716799997'
Test #82:
score: 0
Accepted
time: 1ms
memory: 3280kb
input:
1101000010010000110100000110110101101101110101010110010
output:
142898349874998055
result:
ok answer is '142898349874998055'
Test #83:
score: -100
Wrong Answer
time: 1ms
memory: 3424kb
input:
0111110000111000010101001110010101101111011111111011100
output:
202020552638134501
result:
wrong answer expected '119031467564851955', found '202020552638134501'