QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411333#6299. Binary StringcrsfaaWA 159ms9900kbC++143.0kb2024-05-15 11:40:152024-05-15 11:40:15

Judging History

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

  • [2024-05-15 11:40:15]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:9900kb
  • [2024-05-15 11:40:15]
  • 提交

answer

#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int mxn=1e7+5;
bool t[mxn],t2[mxn];
char s[mxn];
int pre[mxn];
struct seg
{
	int l,r;
	bool v;
	int len()
	{
		return r-l+1;
	}
};
int getp(int n,bool t[])
{
	int i,j;
	for(i=1;i<=n;i++)
		if(n%i==0)
		{
			for(j=i;j<n;j++)
				if(t[j]!=t[j-i])
					goto bre;
			return i;
			bre:;
		}
}
int main()
{
	int T=read();
	while(T--)
	{
		scanf("%s",s+1);
		int n=strlen(s+1),i,j;
		for(i=0;i<n;i++)
			t[i]=s[i+1]-'0';
		for(i=0;i<n;i++)
			if(t[i]!=t[0])
				goto bre;
		puts("1");
		continue;
		bre:;
		vector<seg> a;
		for(i=0;i<n;i++)
			if(t[i]!=t[1])
			{
				for(j=0;j<n;j++)
					t2[j]=t[(j+i)%n];
				memcpy(t,t2,n);
				break;
			}
		for(i=0;i<n;i=j)
		{
			for(j=i;j<n&&t[j]==t[i];j++);
			if(j>i+1)
				a.push_back({i,j-1,t[i]});
		}
		int sum=0;
		for(auto x:a)
			if(x.v)
				sum+=x.len()-1;
			else sum-=x.len()-1;
		if(sum<0)
		{
			for(auto &x:a)
				x.v^=1,x.l=n-1-x.l,x.r=n-1-x.r,swap(x.l,x.r);
			reverse(a.begin(),a.end());
		}
//		for(i=0;i<n;i++)
//			cout<<t[i];
//		puts("");
//		for(auto x:a)
//			cout<<x.l<<' '<<x.r<<' '<<x.v<<endl;
		vector<int> pre{0};
		for(auto x:a)
		{
			int v=(x.v?1:-1)*(x.r-x.l);
			pre.push_back(pre.back()+v);
		}
		assert(pre.back()>=0);
		pre.erase(pre.begin());
		int mn=2e9;
		for(i=0;i<pre.size();i++)
			mn=min(mn,pre[i]);
		for(i=0;i<pre.size();i++)
			if(pre[i]==mn)
			{
				vector<seg> tp;
				int lft=a[(i+1)%pre.size()].l;
				for(j=0;j<pre.size();j++)
				{
//					cout<<':'<<j<<endl;
					seg u=a[(i+1+j)%pre.size()];
					tp.push_back({(u.l-lft+n)%n,(u.r-lft+n)%n,u.v});
				}
				a=tp;
				break;
			}
		sum=0;
		for(auto x:a)
		{
			if(x.v)
				sum+=x.len()-1;
			else sum-=x.len()-1;
			assert(sum>=0);
//			cout<<x.l<<' '<<x.r<<':'<<x.v<<endl;
		}
//		for(auto x:tp)
//		{
//			
//		}
//		for(auto x:a)
//			cout<<x.l<<' '<<x.r<<'#'<<x.v<<endl;
//		for(au)
		int mx=0;
		stack<seg> stk;
		for(auto x:a)
		{
			if(x.v) stk.push(x);
			else
			{
				int l=x.l,r=x.r,s=0;
				for(;;)
				{
					
					assert(stk.size());
//					cout<<l<<' '<<r<<':'<<stk.top().len()<<endl;
//					if(!stk.size()) for(;;);
//					assert(stk.size());
					s+=(l-stk.top().r-1)/2;
					r-=l-(stk.top().r+1);
					l=stk.top().r+1;
//					cout<<s<<':'<<l<<' '<<r<<endl;
					if(stk.top().len()>=r-l+1)
					{
						mx=max(mx,s+r-l);
						break;
					}
					s+=stk.top().len()-1;
					r-=stk.top().len()-1;
					l-=stk.top().len()-1,r-=stk.top().len()-1;
					stk.pop();
				}
			}
		}
//		cout<<mx<<endl;
		memset(t,0,n);
		while(stk.size())
		{
			for(i=stk.top().l;i<=stk.top().r;i++)
				t[i]=1;
			stk.pop();
		}
		printf("%d\n",mx+getp(n,t));
	}
}
/*
1
110100000000000000
*/

详细

Test #1:

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

input:

3
1
001001
0001111

output:

1
3
9

result:

ok 3 number(s): "1 3 9"

Test #2:

score: -100
Wrong Answer
time: 159ms
memory: 9900kb

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
20
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
20
21
20
20
20
21
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
21
21
21
22
23
19
19
19
19
1...

result:

wrong answer 28th numbers differ - expected: '21', found: '20'