QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303013 | #4273. Good Game | C1942huangjiaxu | 0 | 0ms | 3940kb | C++14 | 2.1kb | 2024-01-11 16:50:56 | 2024-01-11 16:50:57 |
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(j);
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];
del(l);
}
int nm=l;
for(int i=l+1,j=r+1;j<=m;++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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3780kb
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: 3940kb
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: 3752kb
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: 3864kb
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: 3660kb
input:
1 B
output:
-1
result:
ok no solution
Test #6:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
2 BB
output:
1 1 2
result:
ok good solution!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
7 AAAABBB
output:
3 1 2 1 2 1 3
result:
ok good solution!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3868kb
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: 3728kb
input:
2 AB
output:
-1
result:
ok no solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
14 BAAAAAAAAAAAAA
output:
-1
result:
ok no solution
Test #11:
score: -3
Wrong Answer
time: 0ms
memory: 3788kb
input:
14 ABBABAABBABBAB
output:
7 2 2 4 2 7 2 4 2 2 2 2 2 1 2
result:
wrong answer invalid operation on step #5: AB
Subtask #2:
score: 0
Runtime Error
Test #51:
score: 6
Accepted
time: 0ms
memory: 3800kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
ok no solution
Test #52:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
300 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...
output:
-1
result:
ok no solution
Test #53:
score: -6
Runtime Error
input:
299 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #102:
score: 0
Runtime Error
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #153:
score: 0
Runtime Error
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...