QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#71315 | #4273. Good Game | zhouhuanyi | 0 | 181ms | 49536kb | C++14 | 3.7kb | 2023-01-09 17:21:17 | 2023-01-09 17:21:19 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<set>
#define N 2000000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int num,data;
bool operator < (const reads &t)const
{
return (data!=t.data)?data>t.data:num<t.num;
}
};
reads st[N+1];
set<reads>s;
int n,length,leng,tong[N+1],pv[N+1],nt[N+1],rt[N+1],L[N+1],R[N+1],sc[N+1];
char c[N+1];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int d)
{
for (;x<=length;x+=lowbit(x)) sc[x]+=d;
return;
}
int query(int x)
{
int res=0;
for (;x>=1;x-=lowbit(x)) res+=sc[x];
return res;
}
void del(int x)
{
int s1=pv[x],s2=nt[x];
nt[s1]=s2,pv[s2]=s1;
if (tong[x]==1)
{
s.erase((reads){rt[x],R[rt[x]]-L[rt[x]]+1});
if (L[rt[x]]==x) L[rt[x]]++;
else R[rt[x]]--;
if (L[rt[x]]<=R[rt[x]]) s.insert((reads){rt[x],R[rt[x]]-L[rt[x]]+1});
}
nt[x]=pv[x]=-1;
return;
}
void solve(int x)
{
for (int i=1;i<=(tong[x]>>1);++i) st[++leng]=(reads){query(x-1)+1,2};
if (tong[x]&1) st[leng].data++;
if (pv[x]&&nt[x]!=length+1) add(pv[x],-tong[pv[x]]),add(nt[x],-tong[nt[x]]),add(x,tong[pv[x]]+tong[nt[x]]-tong[x]),tong[x]=tong[pv[x]]+tong[nt[x]],del(pv[x]),del(nt[x]);
else add(x,-tong[x]),del(x);
return;
}
int main()
{
int d,lst=0,cnt0=0,cnt1=0,cnt,rst=0,mid=0,top;
bool op=1;
n=read();
for (int i=1;i<=n;++i) cin>>c[i];
for (int i=1;i<=n;++i)
if (i==n||c[i]!=c[i+1])
tong[++length]=i-lst,lst=i;
for (int i=1;i<=length;++i) add(i,tong[i]);
for (int i=1;i<=length-1;++i) cnt0+=(tong[i]==1&&tong[i+1]>=2),cnt1+=(tong[i]>=2&&tong[i+1]==1);
for (int i=0;i<=length;++i) nt[i]=i+1,pv[i+1]=i;
for (int i=1;i<=length;++i)
{
if ((i==1||tong[i-1]>=2)&&tong[i]==1) lst=i;
rt[i]=lst;
if ((i==length||tong[i+1]>=2)&&tong[i]==1) L[lst]=lst,R[lst]=i,s.insert((reads){lst,R[lst]-L[lst]+1}),op&=(((i-lst+1)<<1)<=(length-(lst!=1)-(i!=length)));
}
if (tong[1]==1&&cnt0==1&&cnt1==1)
{
cnt0=cnt1=0;
for (int i=1;i<=length;++i)
{
if (tong[i]==1) cnt0++;
else break;
}
for (int i=length;i>=1;--i)
{
if (tong[i]==1) cnt1++;
else break;
}
cnt=length-cnt0-cnt1;
if (cnt>=((n+1)>>1)||((length&1)&&op))
{
puts("Yes");
if (cnt>=((n+1)>>1))
{
for (int i=1;i<=(cnt0<<1);++i) solve(cnt0+1);
for (int i=1;i<=(cnt1<<1);++i) solve(length-cnt1);
for (int i=1;i<=length;++i)
if (nt[i]!=-1)
solve(i);
}
else
{
if (cnt0<cnt1)
{
for (int i=1;i<=cnt1-cnt0;++i) solve(length-cnt1);
}
else
{
for (int i=1;i<=cnt0-cnt1;++i) solve(cnt0+1);
}
cnt=0;
for (int i=1;i<=length;++i)
if (nt[i]!=-1)
cnt++;
for (int i=1;i<=length;++i)
if (nt[i]!=-1)
{
rst++;
if (rst==((cnt+1)>>1)) mid=i;
}
for (int i=1;i<=((cnt+1)>>1);++i) solve(mid);
}
printf("%d\n",leng);
for (int i=1;i<=leng;++i) printf("%d %d\n",st[i].num,st[i].data);
}
else puts("No");
return 0;
}
if (op)
{
puts("Yes");
while (!s.empty())
{
auto it=s.begin();
top=(*it).num,d=(*it).data,it++;
if (s.size()==2&&it!=s.end()&&!pv[L[top]]&&(*it).data==d) top=(*it).num;
if (pv[L[top]]!=-1&&pv[pv[L[top]]]&&tong[pv[L[top]]]>=2) solve(pv[L[top]]);
else solve(nt[R[top]]);
}
for (int i=1;i<=length;++i)
if (nt[i]!=-1)
solve(i);
printf("%d\n",leng);
for (int i=1;i<=leng;++i) printf("%d %d\n",st[i].num,st[i].data);
}
else puts("No");
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 19920kb
input:
9 ABAABBBAA
output:
Yes 4 3 2 2 2 2 2 1 3
result:
wrong output format Expected integer, but "Yes" found
Subtask #2:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 6ms
memory: 19728kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
No
result:
wrong output format Expected integer, but "No" found
Subtask #3:
score: 0
Wrong Answer
Test #102:
score: 0
Wrong Answer
time: 0ms
memory: 19888kb
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
Yes 2998 1996 2 1996 2 3991 2 3991 2 3991 2 3991 3 1995 2 3988 2 1994 2 3985 2 1993 2 3982 2 1992 2 3979 2 1991 2 3976 2 1990 2 3973 2 1989 2 3970 2 1988 2 3967 2 1987 2 3964 2 1986 2 3961 2 1985 2 3958 2 1984 2 3955 2 1983 2 3952 2 1982 2 3949 2 1981 2 3946 2 1980 2 3943 2 1979 2 3940 2 1978 2 3937...
result:
wrong output format Expected integer, but "Yes" found
Subtask #4:
score: 0
Wrong Answer
Test #153:
score: 0
Wrong Answer
time: 181ms
memory: 49536kb
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
Yes 499998 333328 2 333328 2 333328 2 666655 2 666655 2 666655 2 666655 2 666655 2 333327 2 666652 2 333326 2 666649 2 333325 2 666646 2 333324 2 666643 2 333323 2 666640 2 333322 2 666637 2 333321 2 666634 2 333320 2 666631 2 333319 2 666628 2 333318 2 666625 2 333317 2 666622 2 333316 2 666619 2 3...
result:
wrong output format Expected integer, but "Yes" found