QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113425#6628. Flip it and Stick iteyiigjkn0 4ms4016kbC++142.0kb2023-06-17 16:53:172023-06-17 16:53:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-17 16:53:18]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:4016kb
  • [2023-06-17 16:53:17]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
char s[200010],t[5];
int main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	
	mt19937 rnd;
	for(int i=1;i<=(int)2e5;i++) s[i]=rnd()%2+'0';
	t[1]=t[2]=t[3]='1';
	
//	cin>>s+1>>t+1;
	int n=strlen(s+1),m=strlen(t+1);
	auto flp=[&]()
	{
		for(int i=1;i<=n;i++) s[i]='0'+'1'-s[i];
		for(int i=1;i<=m;i++) t[i]='0'+'1'-t[i];
	};
	auto rev=[&]()
	{
		reverse(s+1,s+n+1);
		reverse(t+1,t+m+1);
	};
	if(m==1) cout<<(count_if(s+1,s+n+1,[](char c){return c==t[1];})?-1:0)<<"\n";
	else if(m==2)
	{
		if(t[1]==t[2])// 11
		{
			if(t[1]=='0') flp();
			int c0=(s[1]=='0')+(s[n]=='0'),c1=0;
			for(int i=1;i<n;i++)
				if(s[i]==s[i+1]) (s[i]=='0'?c0:c1)++;
			if(c1<=c0) cout<<c1<<"\n";
			else cout<<"-1\n";
		}
		else// 10
		{
			if(t[1]=='0') flp();
			int l=1,r=n,ans=0;
			while(l<=n && s[l]=='0') l++;
			while(r && s[r]=='1') r--;
			for(int i=l;i<r;i++) ans+=(s[i]=='1' && s[i+1]=='0');
			cout<<ans<<"\n";
		}
	}
	else
	{
		if(t[1]==t[2] && t[1]==t[3])// 111
		{
			if(t[1]=='0') flp();
			int c0=(s[1]=='0')+(s[n]=='0'),c1=0,ans=0,tot=0;
			static int a[200010];
			for(int i=1;i<n;i++) c0+=(s[i]=='0' && s[i+1]=='0');
			for(int i=1;i<=n;i++)
				if(s[i]=='1')
				{
					for(i--,tot++;i<n && s[i+1]=='1';i++) a[tot]++;
					c1+=(a[tot]==1);
					int mn=max(min(c0,a[tot]/2-1),0);
					c0-=mn;a[tot]-=2*mn;ans+=mn;
				}
			if(c0>0)
			{
				for(int i=1;i<=tot && c0;i++)
					if(a[i]==3) c1++,c0--,a[i]--,ans++;
				for(int i=1;i<=tot;i++)
					if(a[i]==3) c1--,a[i]--,ans++;
			}
			else for(int i=1;i<=tot;i++) a[i]=max(a[i]-2,0),c1-=a[i],ans+=a[i];
			cout<<(c1>=0?ans:-1)<<"\n";
		}
		else if(t[1]==t[3])// 010
		{
			if(t[1]=='1') flp();
			int cnt=0;
			for(int i=2;i<n;i++) cnt+=(s[i-1]=='0' && s[i]=='1' && s[i+1]=='0');
			cout<<(cnt+1)/2<<"\n";
		}
		else// 110
		{
			if(t[2]==t[3]) rev();
			if(t[1]=='0') flp();
			int ans=0;
			for(int i=2;i<n;i++) ans+=(s[i-1]=='1' && s[i]=='1' && s[i+1]=='0');
			cout<<ans<<"\n";
		}
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3840kb

input:

1
0

output:

16609

result:

wrong answer 1st numbers differ - expected: '0', found: '16609'

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 4ms
memory: 4016kb

input:

0
01

output:

16609

result:

wrong answer 1st numbers differ - expected: '0', found: '16609'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #40:

score: 0
Wrong Answer
time: 2ms
memory: 3924kb

input:

11
011

output:

16609

result:

wrong answer 1st numbers differ - expected: '0', found: '16609'

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 0
Wrong Answer
time: 4ms
memory: 3956kb

input:

11
011

output:

16609

result:

wrong answer 1st numbers differ - expected: '0', found: '16609'

Subtask #6:

score: 0
Skipped

Dependency #4:

0%