Submission #4557

#TimeUsernameProblemLanguageResultExecution timeMemory
4557aintaBoard (CEOI13_board)C++98
100 / 100
4 ms2748 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...