https://vjudge.net/contest/357844#problem/C
懒得复制了
模拟题,用stl应该很快但是我不会qwq硬写出来了,我真棒。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int ao[1000000],bo[1000000],a[1000000],b[1000000];
int main()
{
int n,top1=0,bot1,top2=0,bot2;
scanf("%d",&n);
int ai;
scanf("%d",&ai);
bot1=ai;
for(int i=0;i<ai;i++)
{
scanf("%d",&a[i]);
ao[i]=a[i];
}
int bi;
scanf("%d",&bi);
bot2=bi;
for(int i=0;i<bi;i++)
{
scanf("%d",&b[i]);
bo[i]=b[i];
}
int casee=0,flag=1;
while(top1<bot1&&top2<bot2&&flag!=0&&bot1<1000000&&bot2<1000000)
{
flag=1;
if(a[top1]<b[top2])
{
b[bot2]=a[top1];
bot2++;
b[bot2]=b[top2];
bot2++;
top1++;
top2++;
}
else
{
a[bot1]=b[top2];
bot1++;
a[bot1]=a[top1];
bot1++;
top1++;top2++;
}
casee++;
if(bot1-top1==ai)
{
int j=0;
flag=0;
for(int i=top1;i<bot1;i++)
{
if(a[i]!=ao[j]) {flag=1;break;}
j++;
}
j=0;
for(int i=top2;i<bot2;i++)
{
if(b[i]!=bo[i]) {flag=1;break;}
j++;
}
}
}
if(flag==0||bot1>=1000000||bot2>=1000000) printf("-1");
else
{
int win;
if(top1>=bot1) win=2;
else win=1;
printf("%d %d",casee,win);
}
return 0;
}