QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#336725 | #6299. Binary String | SATSKY | WA | 479ms | 3816kb | C++20 | 2.5kb | 2024-02-24 20:05:55 | 2024-02-24 20:05:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const int M=998244353;const double eps=1e-10,inf=1e30;
struct node{int v,b,len,tim;};
struct S
{
vector<node>arr;string s;
vector<int>l,r;
bool chk(int L,int segc)
{
if(L%segc)return 0;int B=L/segc;
for(int j=1;j<segc;j++)if(s.substr(0,B)!=s.substr(B*j,B))return 0;return 1;
}
void xlink(int L,int R){l[R]=L,r[L]=R;}
void chk2(int L,int R,queue<int>&Q){if(arr[L].v&&!arr[R].v)Q.push(L);}
void solve()
{
cin>>s;int n=s.length(),res=0;queue<int>Q;
int p=0;for(int i=1;i<n;i++)if(s[i]!=s[0]){p=i;break;}if(!p){cout<<"1\n";return;}
for(int l=p,r;l<p+n;l=r+1)
{
r=l;while(s[(r+1)%n]==s[l%n])r++;
//cout<<l<<"$"<<r<<'\n';
int len=(r-l+1)%n;if(len==1)continue;
if(s[l%n]=='1')arr.push_back({1,l%n,len,0});
else arr.push_back({0,r%n,len,0});
}
//for(auto k:arr)cout<<k.v<<'/'<<k.b<<'/'<<k.len<<'/'<<k.tim<<"\n";
int siz=arr.size();l.resize(siz),r.resize(siz);for(int i=0;i<siz;i++)xlink(i,(i+1)%siz),chk2(i,(i+1)%siz,Q);
for(;!Q.empty();Q.pop())
{
int L=Q.front(),R=r[L],LL=l[L],RR=r[R];int a=arr[L].len,b=arr[R].len,dL=min(a,b)-1;
int tim=((arr[R].b-arr[L].b+n)%n+1-a-b)/2+dL;res=max(res,tim);
arr[L].len-=dL;arr[L].tim=tim;arr[R].len-=dL;arr[R].tim=tim;
//cout<<L<<','<<arr[L].len<<"|"<<R<<','<<arr[R].len<<"\n";
if(arr[L].len==1&&arr[R].len==1){if(LL==L)continue;xlink(LL,RR);chk2(LL,RR,Q);}
else if(arr[L].len==1)xlink(LL,R),chk2(LL,R,Q);else xlink(L,RR),chk2(L,RR,Q);
}
for(auto &k:s)k='2';
for(auto &k:arr)if(k.len!=1)
{
if(k.v)
{
for(int p=k.b+res,cnt=k.len;cnt;cnt--,p++)s[(p%n+n)%n]='1';
}
else
{
for(int p=k.b-res,cnt=k.len;cnt;cnt--,p--)s[(p%n+n)%n]='0';
}
}
//cout<<s<<'\n';
for(int i=n;i<n*3;i++)if(s[i%n]=='2')
{
char c=s[(i-1)%n];
if(c=='0')s[i%n]='1';
if(c=='1')s[i%n]='0';
}
//cout<<s<<'\n';
if(s[0]=='2') { cout<<res+2<<'\n';return; }
int lft=n,segc=1;
for(int i=2;i*i<=lft;i++)if(lft%i==0)
{
int L=n;while(chk(L,i))L/=i,segc*=i;
while(lft%i==0)lft/=i;
}
//if(chk(n,lft))segc*=lft;
//cout<<segc<<"|\n";
cout<<res+n/segc<<'\n';
}
};
void precal()
{
}
int main()
{
//freopen("1.in","r",stdin);
cout<<fixed<<setprecision(12);
ios::sync_with_stdio(0);cin.tie(0);precal();
//int n;cin>>n;for(int i=18;i;i--)cout<<n%2,n>>=1;return 0;
int t=1;cin>>t;
//clock_t a=clock();
while(t--){S SS;SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: 0
Accepted
time: 149ms
memory: 3756kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
1 18 18 19 18 18 19 20 18 18 18 20 19 19 20 21 18 18 18 19 18 18 20 21 19 19 19 21 20 20 21 22 18 18 18 19 18 18 19 21 18 18 18 21 20 20 21 22 19 19 19 19 19 19 21 22 20 20 20 22 21 21 22 23 18 18 18 19 18 18 19 20 18 18 18 20 19 19 21 22 18 18 18 19 18 18 21 22 20 20 20 22 21 21 22 23 19 19 19 19 1...
result:
ok 262144 numbers
Test #3:
score: 0
Accepted
time: 292ms
memory: 3548kb
input:
524288 0000000000000000000 1000000000000000000 0100000000000000000 1100000000000000000 0010000000000000000 1010000000000000000 0110000000000000000 1110000000000000000 0001000000000000000 1001000000000000000 0101000000000000000 1101000000000000000 0011000000000000000 1011000000000000000 0111000000000...
output:
1 19 19 20 19 19 20 21 19 19 19 21 20 20 21 22 19 19 19 20 19 19 21 22 20 20 20 22 21 21 22 23 19 19 19 20 19 19 20 22 19 19 19 22 21 21 22 23 20 20 20 20 20 20 22 23 21 21 21 23 22 22 23 24 19 19 19 20 19 19 20 21 19 19 19 21 20 20 22 23 19 19 19 20 19 19 22 23 21 21 21 23 22 22 23 24 20 20 20 20 2...
result:
ok 524288 numbers
Test #4:
score: -100
Wrong Answer
time: 479ms
memory: 3816kb
input:
952358 0011101111 101010101101 101111111010100 0101011000110001100 0101111101110 010 100100000111011 011010110110011 1010111 1 1111101010 11111011001111110 0101101101011 001 1100111100 100011 10 10 0001 011100 1100010 111111101010010 01001111110011011 01100 1010 10101111 01000111100011111110 10101 0...
output:
11 12 18 20 14 3 21 16 7 1 10 18 13 3 11 4 2 2 4 4 8 18 19 6 2 8 24 5 1 1 5 25 1 14 1 15 20 3 7 24 12 10 20 21 23 1 22 18 22 5 1 6 18 12 1 4 5 12 13 12 21 1 5 12 21 8 1 8 18 4 1 12 13 6 3 3 16 6 8 1 1 17 1 1 1 6 6 4 4 10 7 5 4 5 24 6 11 4 8 15 3 9 9 19 5 16 11 5 6 9 17 1 25 14 6 1 4 20 1 4 20 14 14 ...
result:
wrong answer 6339th numbers differ - expected: '4', found: '12'