QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#256542 | #6299. Binary String | SATSKY | WA | 164ms | 3624kb | C++20 | 2.4kb | 2023-11-18 19:58:33 | 2023-11-18 19:58:34 |
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+k.tim,cnt=k.len;cnt;cnt--,p++)s[(p%n+n)%n]='1';
}
else
{
for(int p=k.b-k.tim,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 t=1;cin>>t;
//clock_t a=clock();
while(t--){S SS;SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3496kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 164ms
memory: 3624kb
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:
wrong answer 770th numbers differ - expected: '19', found: '10'