QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72219#4273. Good GamePittow0 7ms16580kbC++141.3kb2023-01-15 09:47:332023-01-15 09:47:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 09:47:34]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:16580kb
  • [2023-01-15 09:47:33]
  • 提交

answer

#include<stdio.h>
typedef unsigned int u32;
u32 n,i,a[1000086];
u32 m,j,s[1000086],g[1000086];

u32 c,p[500086],u[500086];
void del(u32 x,u32 l){
	u[c]=l;
	p[c++]=x;
}void print(){
	for(i=0;i<c;++i)n-=u[i];
	if(n)c=0;
	if(c==0){
		puts("-1");
		return;
	}printf("%u\n",c);
	for(i=0;i<c;++i)
	printf("%u %u\n",p[i]+1,u[i]);
}void clear(u32 p,u32 l){
	if(l&1)del(p,3),l-=3;
	while(l)del(p,2),l-=2;
}void odd(u32 *s,u32 m){
	g[0]=s[0];
	for(i=1;i<m;++i)g[i]=g[i-1]+s[i];
	if(s[m>>1]>1){
		clear(g[m>>1]-s[m>>1],s[m>>1]);
		for(i=(m>>1)-1;i<m;--i)
		clear(g[i]-s[i],s[i]+s[m-1-i]);
	}else{
		for(i=m>>1;i&&s[i-1]==1;--i);
		for(j=m>>1;j<m&&s[j]==1;++j);
		if((j-i)*2<m){
			clear(g[j]-s[j],s[j]);
			for(u32 k=j+1;k+1<m&&j+j>i+i+k;++k)
			clear(g[k]-s[k],s[k]+s[j+j-k]);
			if(i)clear(g[i-1]-s[i-1],s[i-1]);
			for(u32 k=i-2;k&&k<m;--k)
			clear(g[k]-s[k],s[k]+s[i+i-k]);
			clear(0,s[0]+s[i+i]+s[m-1]);
		}
	}
}int main(){
	scanf("%u",&n);
	for(i=0;i<n;++i){
		char c;
		while(c=getchar(),c<'A'||c>'B');
		if(c=='A')a[i]=1;
	}for(i=j=0;i<n;i=j,++m)
	while(j<n&&a[j]==a[i])++j,++s[m];
	if(a[0]==a[n-1])odd(s,m);
	else if(s[0]>1||s[m-1]>1){
		if(s[0]>1)clear(0,s[0]),odd(s+1,m-1);
		else clear(n-s[m-1],s[m-1]),odd(s,m-1);
	}else odd(s,m>>1),odd(s+(m>>1),m>>1);
	print();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 7720kb

input:

9
ABAABBBAA

output:

4
3 2
2 2
2 2
1 3

result:

ok good solution!

Test #2:

score: -3
Wrong Answer
time: 0ms
memory: 9620kb

input:

13
ABABBABABBABA

output:

-1

result:

wrong answer you didn't find a solution but jury did

Subtask #2:

score: 0
Wrong Answer

Test #51:

score: 6
Accepted
time: 3ms
memory: 9660kb

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

ok no solution

Test #52:

score: 0
Accepted
time: 2ms
memory: 9676kb

input:

300
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...

output:

-1

result:

ok no solution

Test #53:

score: -6
Wrong Answer
time: 2ms
memory: 9576kb

input:

299
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

-1

result:

wrong answer you didn't find a solution but jury did

Subtask #3:

score: 0
Wrong Answer

Test #102:

score: 0
Wrong Answer
time: 1ms
memory: 7640kb

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

-1

result:

wrong answer you didn't find a solution but jury did

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 0
Wrong Answer
time: 7ms
memory: 16580kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

wrong answer you didn't find a solution but jury did