QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72238#4273. Good GamePittow0 52ms17192kbC++141.3kb2023-01-15 10:44:162023-01-15 10:44:17

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 10:44:17]
  • 评测
  • 测评结果:0
  • 用时:52ms
  • 内存:17192kb
  • [2023-01-15 10:44:16]
  • 提交

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+2>=i+i+k;++k)
			clear(g[j+j-k]-s[j+j-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[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;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 3ms
memory: 9748kb

input:

9
ABAABBBAA

output:

4
3 2
2 2
2 2
1 3

result:

ok good solution!

Test #2:

score: 0
Accepted
time: 3ms
memory: 9800kb

input:

13
ABABBABABBABA

output:

6
9 2
8 2
4 2
3 2
2 3
1 2

result:

ok good solution!

Test #3:

score: 0
Accepted
time: 0ms
memory: 7728kb

input:

15
AABABAABABAABAB

output:

7
1 2
9 2
8 2
4 2
3 2
2 3
1 2

result:

ok good solution!

Test #4:

score: 0
Accepted
time: 1ms
memory: 9788kb

input:

15
ABAABBBABAABBAB

output:

7
3 2
2 2
2 2
1 2
4 2
2 3
1 2

result:

ok good solution!

Test #5:

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

input:

1
B

output:

-1

result:

ok no solution

Test #6:

score: 0
Accepted
time: 1ms
memory: 9804kb

input:

2
BB

output:

1
1 2

result:

ok good solution!

Test #7:

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

input:

7
AAAABBB

output:

3
1 2
1 2
1 3

result:

ok good solution!

Test #8:

score: 0
Accepted
time: 0ms
memory: 7748kb

input:

11
BBBBBBAAAAA

output:

5
1 2
1 2
1 2
1 3
1 2

result:

ok good solution!

Test #9:

score: 0
Accepted
time: 1ms
memory: 7624kb

input:

2
AB

output:

-1

result:

ok no solution

Test #10:

score: -3
Wrong Answer
time: 2ms
memory: 7728kb

input:

14
BAAAAAAAAAAAAA

output:

6
2 3
2 2
2 2
2 2
2 2
2 2

result:

wrong answer wrong solution (expected NO SOLUTION)

Subtask #2:

score: 0
Wrong Answer

Test #51:

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

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

66
67 2
65 2
65 2
63 2
63 2
61 2
61 2
59 2
59 2
57 2
57 2
55 2
55 2
53 2
53 2
51 2
51 2
48 3
48 2
46 2
46 2
44 2
44 2
42 2
42 2
40 2
40 2
38 2
38 2
36 2
36 2
34 2
34 2
33 3
32 3
31 3
30 3
29 3
28 3
27 3
26 3
25 3
24 3
23 3
22 3
21 3
20 3
19 3
18 3
17 3
16 3
15 3
14 3
13 3
12 3
11 3
10 3
9 3
8 3
7 3
...

result:

wrong answer wrong solution (expected NO SOLUTION)

Subtask #3:

score: 0
Wrong Answer

Test #102:

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

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

2006
3995 3
3995 2
3995 2
3995 2
3994 2
1996 2
1996 2
1995 2
1994 2
1993 2
1992 2
1991 2
1990 2
1989 2
1988 2
1987 2
1986 2
1985 2
1984 2
1983 2
1982 2
1981 2
1980 2
1979 2
1978 2
1977 2
1976 2
1975 2
1974 2
1973 2
1972 2
1971 2
1970 2
1969 2
1968 2
1967 2
1966 2
1965 2
1964 2
1963 2
1962 2
1961 2
1...

result:

wrong answer invalid operation on step #2002: AB

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 0
Wrong Answer
time: 52ms
memory: 17192kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

333340
666661 2
666661 2
666661 2
666661 2
666661 2
666660 2
333328 2
333328 2
333328 2
333327 2
333326 2
333325 2
333324 2
333323 2
333322 2
333321 2
333320 2
333319 2
333318 2
333317 2
333316 2
333315 2
333314 2
333313 2
333312 2
333311 2
333310 2
333309 2
333308 2
333307 2
333306 2
333305 2
33330...

result:

wrong answer invalid operation on step #333336: AB