이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
int st[100100][2],top,i,x,a[100100],b[100100],c1,c2;
char p[101000];
void Do(){
for(i=0;p[i];i++){
if(p[i]<='2'){
p[i]-='0';
if(st[top][0]==p[i])st[top][1]++;
else{
st[++top][0]=p[i];
st[top][1]=1;
}
continue;
}
if(p[i]=='U'){
st[top][1]--;
if(!st[top][1])top--;
continue;
}
if(p[i]=='L')x=1;
else x=2;
if(x==st[top][0]){
if(st[top-1][1]>1){
st[top-1][1]--;
st[top+1][0]=3-x;
st[top+1][1]=st[top][1];
st[top][0]=x;
st[top][1]=1;
top++;
}
else{
if(top>2){
st[top-2][1]++;
st[top-1][1]=st[top][1];
top--;
}
else{
st[top-1][0]=x;
st[top][0]=3-x;
}
}
continue;
}
if(st[top][1]>1){
st[top][1]--;
st[++top][0]=x;
st[top][1]=1;
}
else{
if(top>1){
st[top-1][1]++;
top--;
}
else st[top][0]=x;
}
}
}
int main()
{
int Res,x=0;
scanf("%s",p);
Do();
for(i=1;i<=top;i++)
while(st[i][1]--)a[c1++]=st[i][0];
top=0;
scanf("%s",p);
Do();
for(i=1;i<=top;i++)
while(st[i][1]--)b[c2++]=st[i][0];
if(c1>c2)Res=c1-c2,c1=c2;
else Res=c2-c1;
for(i=0;i<c1;i++){
x*=2;
x+=(a[i]-b[i]);
if(x>3 || x<-3){
x-=(a[i]-b[i]);
x/=2;
Res+=(c1-i)*2;
break;
}
}
if(x<0)x=-x;
Res+=x;
printf("%d\n",Res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |