QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77374 | #4273. Good Game | huzhaoyang | 0 | 122ms | 22000kb | C++14 | 1.6kb | 2023-02-14 15:08:30 | 2023-02-14 15:08:33 |
Judging History
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]);
printf("%d\n",m);
for(int i=1;i<=m;i++)printf("%d ",a[i]);
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;
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: 0
Wrong Answer
time: 2ms
memory: 5476kb
input:
9 ABAABBBAA
output:
5 1 1 2 3 2 4 3 2 4 2 2 2 1 3
result:
wrong answer Integer 1 violates the range [2, 3]
Subtask #2:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 0ms
memory: 5484kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
198 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer wrong solution (expected NO SOLUTION)
Subtask #3:
score: 0
Wrong Answer
Test #102:
score: 0
Wrong Answer
time: 1ms
memory: 5792kb
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
5987 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer Integer 1 violates the range [2, 3]
Subtask #4:
score: 0
Wrong Answer
Test #153:
score: 0
Wrong Answer
time: 122ms
memory: 22000kb
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
999983 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer Integer 1 violates the range [2, 3]