QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77371#4273. Good Gamehuzhaoyang0 69ms20176kbC++141.6kb2023-02-14 15:04:422023-02-14 15:04:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-14 15:04:45]
  • 评测
  • 测评结果:0
  • 用时:69ms
  • 内存:20176kb
  • [2023-02-14 15:04:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,m,a[N],pre[N],nex[N];
char s[N];
vector<pair<int,int> >ans;
bool check(int l,int r){
	if (l==r)return a[l]>1;
	int mid=(l+r>>1);
	int x=max(pre[mid],l),y=min(nex[mid],r);
	return (y-x<=(r-l>>1));
}
void clr(int l,int r){
	int len=r-l+1;
	for(int i=r-1;i>l+1;i-=2)ans.push_back(make_pair(i,2));
	ans.push_back(make_pair(l,2+(len&1)));
} 
void work(int l,int r){
	int mid=(l+r>>1),s=0;
	int x=max(pre[mid],l),y=min(nex[mid],r);
	for(int i=1;i<y;i++)s+=a[i];
	int k=mid-x;
	if (k){
		clr(s+1,s+a[y]);
		for(int i=1;i<k;i++){
			clr(s-a[y-i]+1,s+a[y+i]);
			s-=a[y-i];
		}
		if (y+k<r)a[y-k]+=a[y+k];
		for(int i=y+k+1;i<=r;i++)a[y-k+(i-y-k)]=a[i];
	}
	s=0;
	for(int i=1;i<x;i++)s+=a[i];
	clr(s+1,s+a[x]);
	for(int i=1;i<=x-l;i++){
		clr(s-a[x-i]+1,s+a[x+i]);
		s-=a[x-i];
	}
}
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1,j=1;i<=n;i=j){
		while ((j<=n)&&(s[i]==s[j]))j++;
		a[++m]=j-i;
	}
	for(int i=1;i<=m;i++)pre[i]=(a[i]>1 ? i : pre[i-1]);
	nex[m+1]=m+1;
	for(int i=m;i;i--)nex[i]=(a[i]>1 ? i : nex[i+1]);
	if (m&1){
		if (check(1,m))work(1,m);
		else{
			puts("-1");
			return 0;
		}
	}
	else{
		bool flag=0;
		for(int i=1;i<=m;i+=2)
			if ((check(1,i))&&(check(i+1,m))){
				int s=0;
				printf("%d ",i);
				for(int j=1;j<=i;j++)s+=a[j];
				flag=1,work(i+1,m),work(1,i);
				break;
			}
		if (!flag){
			puts("-1");
			return 0;
		}
	}
	printf("%d\n",ans.size());
	for(pair<int,int>i:ans)printf("%d %d\n",i.first,i.second);
	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: 3ms
memory: 5472kb

input:

9
ABAABBBAA

output:

4
3 2
4 2
2 2
1 3

result:

ok good solution!

Test #2:

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

input:

13
ABABBABABBABA

output:

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

result:

ok good solution!

Test #3:

score: -3
Wrong Answer
time: 3ms
memory: 9800kb

input:

15
AABABAABABAABAB

output:

1 7
11 2
10 2
6 2
5 2
4 3
3 2
1 2

result:

wrong answer Integer 11 violates the range [2, 3]

Subtask #2:

score: 0
Wrong Answer

Test #51:

score: 6
Accepted
time: 1ms
memory: 5580kb

input:

299
ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

-1

result:

ok no solution

Test #52:

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

input:

300
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...

output:

-1

result:

ok no solution

Test #53:

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

input:

299
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

149
203 2
201 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
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
15...

result:

ok good solution!

Test #54:

score: -6
Wrong Answer
time: 3ms
memory: 9600kb

input:

299
BBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

1 148
203 2
200 3
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
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
...

result:

wrong answer Integer 203 violates the range [2, 3]

Subtask #3:

score: 0
Wrong Answer

Test #102:

score: 7
Accepted
time: 3ms
memory: 5664kb

input:

5998
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

2998
4002 2
4000 2
3998 2
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
3...

result:

ok good solution!

Test #103:

score: -7
Wrong Answer
time: 4ms
memory: 9868kb

input:

5999
BBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

1 2998
4003 2
4000 3
3999 2
3998 2
3997 2
3996 2
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...

result:

wrong answer Integer 4003 violates the range [2, 3]

Subtask #4:

score: 0
Wrong Answer

Test #153:

score: 9
Accepted
time: 69ms
memory: 20064kb

input:

999997
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

499998
666669 2
666667 2
666665 2
666663 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
66663...

result:

ok good solution!

Test #154:

score: -9
Wrong Answer
time: 53ms
memory: 20176kb

input:

999998
BBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

1 499998
666670 2
666667 3
666666 2
666665 2
666664 2
666663 2
666662 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
666...

result:

wrong answer Integer 666670 violates the range [2, 3]