QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72240 | #4273. Good Game | Pittow | 0 | 7ms | 17084kb | C++14 | 1.3kb | 2023-01-15 10:44:53 | 2023-01-15 10:45:00 |
Judging History
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: 9756kb
input:
9 ABAABBBAA
output:
4 3 2 2 2 2 2 1 3
result:
ok good solution!
Test #2:
score: 0
Accepted
time: 1ms
memory: 9748kb
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: 0ms
memory: 9776kb
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: 7588kb
input:
1 B
output:
-1
result:
ok no solution
Test #6:
score: 0
Accepted
time: 0ms
memory: 9792kb
input:
2 BB
output:
1 1 2
result:
ok good solution!
Test #7:
score: 0
Accepted
time: 2ms
memory: 7744kb
input:
7 AAAABBB
output:
3 1 2 1 2 1 3
result:
ok good solution!
Test #8:
score: 0
Accepted
time: 0ms
memory: 7720kb
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: 2ms
memory: 7632kb
input:
2 AB
output:
-1
result:
ok no solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 5488kb
input:
14 BAAAAAAAAAAAAA
output:
-1
result:
ok no solution
Test #11:
score: -3
Wrong Answer
time: 3ms
memory: 9700kb
input:
14 ABBABAABBABBAB
output:
6 6 2 2 2 1 3 4 2 3 2 1 3
result:
wrong answer invalid operation on step #3: AAB
Subtask #2:
score: 0
Wrong Answer
Test #51:
score: 6
Accepted
time: 3ms
memory: 9612kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
ok no solution
Test #52:
score: 0
Accepted
time: 1ms
memory: 9568kb
input:
300 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...
output:
-1
result:
ok no solution
Test #53:
score: -6
Wrong Answer
time: 3ms
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: 3ms
memory: 9712kb
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: 17084kb
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
wrong answer you didn't find a solution but jury did