QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303030#4273. Good GameC1942huangjiaxu0 51ms17872kbC++142.2kb2024-01-11 17:00:222024-01-11 17:00:23

Judging History

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

  • [2024-01-11 17:00:23]
  • 评测
  • 测评结果:0
  • 用时:51ms
  • 内存:17872kb
  • [2024-01-11 17:00:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,ln[N],m,a[N],c,s[N];
char S[N];
vector<pair<int,int> >ans;
void print(){
	printf("%d\n",ans.size());
	for(auto [x,y]:ans)printf("%d %d\n",x,y);
}
void add(int x,int y){
	ans.push_back({x,y});
}
void del(int u){
	int p=s[u-1]+1;
	while(ln[u]>4){
		add(p,3);
		ln[u]-=3;
	}
	if(ln[u]==4)add(p,2),add(p,2);
	else if(ln[u]==3)add(p,3);
	else add(p,2);
}
void work1(){
	int u=a[1];
	if(u-1!=m-u){
		puts("-1");
		exit(0);
	}
	del(u);
	for(int i=u-1;i;--i)add(i,2);
}
void check(){
	if(c==1){
		work1();
		print();
		exit(0);
	}
	a[c+1]=m+1;
	int mx=a[1]-1;
	for(int i=1;i<=c;++i)mx=max(mx,a[i+1]-a[i]-1);
	if(mx*2+1>m){
		puts("-1");
		exit(0);
	}
}
void cut(){
	if(c==2&&a[2]-a[1]-1-(a[1]-1)==m-a[2]||c!=2&&a[1]-1<m-a[c]){
		int u=a[1];
		del(u);
		int nm=u+1;
		for(int i=u-1,j=u+1;i;--i,++j){
			ln[i]+=ln[j];
			del(i);
			nm=j+1;
		}
		for(int i=nm;i<=m;++i)ln[i-nm+1]=ln[i];
		c=0,m=m-nm+1;
		for(int i=1;i<=m;++i)if(ln[i]>1)a[++c]=i;
		for(int i=1;i<=m;++i)s[i]=s[i-1]+ln[i];
	}else{
		int u=a[c];
		del(u);
		int nm=u-1;
		for(int i=u+1,j=u-1;i<=m;++i,--j){
			ln[j]+=ln[i];
			del(j);
			nm=j-1;
		}
		c=0,m=nm;
		for(int i=1;i<=m;++i)if(ln[i]>1)a[++c]=i;
	}
}
void Del(int c,int p){
	int l=p,r=p;
	for(;c;++r,--l,--c){
		ln[l-1]+=ln[r+1];
		if(l-1<1||r+1>m){
			puts("-1");
			exit(0);
		}
		del(l);
	}
	int nm=l;
	for(int i=l+1,j=r+1;j<=m;++i,++j){
		nm=i;
		ln[i]=ln[j];
	}
	m=nm,c=0;
	for(int i=1;i<=m;++i)if(ln[i]>1)a[++c]=i;
	for(int i=1;i<=m;++i)s[i]=s[i-1]+ln[i];
}
int main(){
	scanf("%d%s",&n,S+1);
	for(int i=1,j;j=i,i<=n;i=j+1){
		while(j<n&&S[j+1]==S[i])++j;
		ln[++m]=j-i+1,s[m]=s[m-1]+ln[m];
		if(ln[m]>1)a[++c]=m;
	}
	if(!c)return puts("-1"),0;
	check();
	if(!(m&1)){
		cut();
		check();
	}
	assert(m&1);
	int o=1,mid=(m+1)/2;
	while(a[o+1]<=mid)++o;
	if(a[o]!=mid){
		if(mid-a[o]<=a[o+1]-mid)Del(mid-a[o],a[o+1]);
		else Del(a[o+1]-mid,a[o]);
	}
	o=1,mid=(m+1)/2;
	while(a[o+1]<=mid)++o;
	assert(a[o]==mid);
	for(int i=a[o],j=a[o];i;--i,++j){
		ln[i-1]+=ln[j+1];
		del(i);
	}
	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: 3936kb

input:

9
ABAABBBAA

output:

4
3 2
2 2
2 2
1 3

result:

ok good solution!

Test #2:

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

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: 3904kb

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: 3852kb

input:

15
ABAABBBABAABBAB

output:

7
12 2
10 3
9 2
3 2
2 2
2 2
1 2

result:

ok good solution!

Test #5:

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

input:

1
B

output:

-1

result:

ok no solution

Test #6:

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

input:

2
BB

output:

1
1 2

result:

ok good solution!

Test #7:

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

input:

7
AAAABBB

output:

3
1 2
1 2
1 3

result:

ok good solution!

Test #8:

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

input:

11
BBBBBBAAAAA

output:

4
1 3
1 3
1 3
1 2

result:

ok good solution!

Test #9:

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

input:

2
AB

output:

-1

result:

ok no solution

Test #10:

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

input:

14
BAAAAAAAAAAAAA

output:

-1

result:

ok no solution

Test #11:

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

input:

14
ABBABAABBABBAB

output:

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

result:

ok good solution!

Test #12:

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

input:

15
BAABABABBABBAAB

output:

6
2 2
6 2
5 2
4 3
3 3
1 3

result:

ok good solution!

Test #13:

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

input:

14
BABBBBBBBBBBAB

output:

6
3 3
3 3
3 2
3 2
2 2
1 2

result:

ok good solution!

Test #14:

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

input:

15
BABAAAAAAAAABAB

output:

6
4 3
4 3
4 3
3 2
2 2
1 2

result:

ok good solution!

Test #15:

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

input:

14
BBBABAAAAAAABA

output:

6
1 3
3 3
3 2
3 2
2 2
1 2

result:

ok good solution!

Test #16:

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

input:

15
AAAABABAAAAABAB

output:

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

result:

ok good solution!

Test #17:

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

input:

14
BAAABABAAAABAB

output:

6
2 3
5 2
5 2
4 2
3 2
1 3

result:

ok good solution!

Test #18:

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

input:

15
ABAAAABABBBBABA

output:

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

result:

ok good solution!

Test #19:

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

input:

14
BABAAABAAAABAB

output:

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

result:

ok good solution!

Test #20:

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

input:

15
BABBABABBBBBBAB

output:

6
8 3
8 3
7 2
3 2
2 2
1 3

result:

ok good solution!

Test #21:

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

input:

14
BABAAAABABBBAB

output:

6
10 3
4 2
4 2
3 2
2 3
1 2

result:

ok good solution!

Test #22:

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

input:

15
BABAAAAAABABAAB

output:

6
13 2
4 3
4 3
3 2
2 2
1 3

result:

ok good solution!

Test #23:

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

input:

14
BABBBBBABAAAAA

output:

6
3 3
3 2
2 2
1 2
1 3
1 2

result:

ok good solution!

Test #24:

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

input:

15
BABAAAABABAAAAA

output:

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

result:

ok good solution!

Test #25:

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

input:

15
BAABABAABAABBAA

output:

7
14 2
2 2
5 2
4 2
3 3
1 2
1 2

result:

ok good solution!

Test #26:

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

input:

15
AABAABBAABAABAB

output:

7
1 2
9 2
6 2
4 2
4 2
2 3
1 2

result:

ok good solution!

Test #27:

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

input:

15
AABABBABAABBABB

output:

7
14 2
9 2
5 2
4 2
3 2
3 2
1 3

result:

ok good solution!

Test #28:

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

input:

15
BAABBABBAABABBA

output:

7
13 2
12 2
7 2
4 2
2 3
2 2
1 2

result:

ok good solution!

Test #29:

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

input:

15
BBAABBABABABBAA

output:

-1

result:

ok no solution

Test #30:

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

input:

15
ABABBAABBAABBAB

output:

-1

result:

ok no solution

Test #31:

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

input:

14
AAABAAAAABAAAB

output:

5
1 3
8 3
2 3
2 2
1 3

result:

ok good solution!

Test #32:

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

input:

15
ABBBBABBBBBABBB

output:

6
13 3
7 3
7 2
2 2
2 2
1 3

result:

ok good solution!

Test #33:

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

input:

14
BBBBABBABAAABA

output:

6
1 2
1 2
2 2
4 3
3 2
1 3

result:

ok good solution!

Test #34:

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

input:

15
AAAAABABBBABBAB

output:

6
1 3
1 2
7 2
3 3
2 3
1 2

result:

ok good solution!

Test #35:

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

input:

14
AABABBBBABAAAB

output:

6
1 2
9 3
3 2
3 2
2 2
1 3

result:

ok good solution!

Test #36:

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

input:

15
BAABAAAABABBBBA

output:

7
11 2
11 2
10 2
5 2
5 2
2 2
1 3

result:

ok good solution!

Test #37:

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

input:

14
ABBBABAAABAAAB

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: 0ms
memory: 3576kb

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

ok no solution

Test #52:

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

input:

300
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...

output:

-1

result:

ok no solution

Test #53:

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

input:

299
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

147
199 3
199 3
198 2
197 2
196 2
195 2
194 2
193 2
192 2
191 2
190 2
189 2
188 2
187 2
186 2
185 2
184 2
183 2
182 2
181 2
180 2
179 2
178 2
177 2
176 2
175 2
174 2
173 2
172 2
171 2
170 2
169 2
168 2
167 2
166 2
165 2
164 2
163 2
162 2
161 2
160 2
159 2
158 2
157 2
156 2
155 2
154 2
153 2
152 2
96...

result:

ok good solution!

Test #54:

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

input:

299
BBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

147
1 3
1 3
194 3
194 2
193 2
192 2
191 2
190 2
189 2
188 2
187 2
186 2
185 2
184 2
183 2
182 2
181 2
180 2
179 2
178 2
177 2
176 2
175 2
174 2
173 2
172 2
171 2
170 2
169 2
168 2
167 2
166 2
165 2
164 2
163 2
162 2
161 2
160 2
159 2
158 2
157 2
156 2
155 2
154 2
153 2
152 2
151 2
150 2
149 2
148 2
...

result:

ok good solution!

Test #55:

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

input:

297
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBAABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA

output:

148
224 2
222 3
221 2
220 2
219 2
218 2
217 2
216 2
215 2
214 2
213 2
212 2
211 2
210 2
209 2
208 2
207 2
206 2
205 2
204 2
203 2
202 2
201 2
200 2
199 2
198 2
197 2
196 2
195 2
194 2
193 2
192 2
191 2
190 2
189 2
188 2
187 2
186 2
185 2
184 2
183 2
182 2
181 2
180 2
179 2
178 2
177 2
176 2
175 2
17...

result:

ok good solution!

Test #56:

score: -6
Wrong Answer
time: 1ms
memory: 3808kb

input:

300
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABAAAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBAAABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #102:

score: 7
Accepted
time: 0ms
memory: 3928kb

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

2997
3995 3
3995 3
3995 3
3994 2
3993 2
3992 2
3991 2
3990 2
3989 2
3988 2
3987 2
3986 2
3985 2
3984 2
3983 2
3982 2
3981 2
3980 2
3979 2
3978 2
3977 2
3976 2
3975 2
3974 2
3973 2
3972 2
3971 2
3970 2
3969 2
3968 2
3967 2
3966 2
3965 2
3964 2
3963 2
3962 2
3961 2
3960 2
3959 2
3958 2
3957 2
3956 2
3...

result:

ok good solution!

Test #103:

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

input:

5999
BBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

2998
1 3
1 2
3995 3
3995 2
3994 2
3993 2
3992 2
3991 2
3990 2
3989 2
3988 2
3987 2
3986 2
3985 2
3984 2
3983 2
3982 2
3981 2
3980 2
3979 2
3978 2
3977 2
3976 2
3975 2
3974 2
3973 2
3972 2
3971 2
3970 2
3969 2
3968 2
3967 2
3966 2
3965 2
3964 2
3963 2
3962 2
3961 2
3960 2
3959 2
3958 2
3957 2
3956 2
...

result:

ok good solution!

Test #104:

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

input:

5998
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

2998
4500 2
4497 2
4497 2
4496 2
4495 2
4494 2
4493 2
4492 2
4491 2
4490 2
4489 2
4488 2
4487 2
4486 2
4485 2
4484 2
4483 2
4482 2
4481 2
4480 2
4479 2
4478 2
4477 2
4476 2
4475 2
4474 2
4473 2
4472 2
4471 2
4470 2
4469 2
4468 2
4467 2
4466 2
4465 2
4464 2
4463 2
4462 2
4461 2
4460 2
4459 2
4458 2
4...

result:

ok good solution!

Test #105:

score: -7
Wrong Answer
time: 1ms
memory: 3664kb

input:

5998
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 9
Accepted
time: 37ms
memory: 16344kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

499996
666661 3
666661 3
666661 2
666661 2
666660 2
666659 2
666658 2
666657 2
666656 2
666655 2
666654 2
666653 2
666652 2
666651 2
666650 2
666649 2
666648 2
666647 2
666646 2
666645 2
666644 2
666643 2
666642 2
666641 2
666640 2
666639 2
666638 2
666637 2
666636 2
666635 2
666634 2
666633 2
66663...

result:

ok good solution!

Test #154:

score: 0
Accepted
time: 51ms
memory: 17872kb

input:

999998
BBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

499996
1 3
1 3
666661 3
666661 2
666660 2
666659 2
666658 2
666657 2
666656 2
666655 2
666654 2
666653 2
666652 2
666651 2
666650 2
666649 2
666648 2
666647 2
666646 2
666645 2
666644 2
666643 2
666642 2
666641 2
666640 2
666639 2
666638 2
666637 2
666636 2
666635 2
666634 2
666633 2
666632 2
666631...

result:

ok good solution!

Test #155:

score: 0
Accepted
time: 48ms
memory: 16792kb

input:

999997
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

499998
749999 2
749997 3
749996 2
749995 2
749994 2
749993 2
749992 2
749991 2
749990 2
749989 2
749988 2
749987 2
749986 2
749985 2
749984 2
749983 2
749982 2
749981 2
749980 2
749979 2
749978 2
749977 2
749976 2
749975 2
749974 2
749973 2
749972 2
749971 2
749970 2
749969 2
749968 2
749967 2
74996...

result:

ok good solution!

Test #156:

score: -9
Wrong Answer
time: 10ms
memory: 13936kb

input:

999998
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

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