Submission #5919

#TimeUsernameProblemLanguageResultExecution timeMemory
5919aintaBoard (CEOI13_board)C++98
100 / 100
4 ms2764 KiB
#pragma warning(disable:4996) #include<stdio.h> struct Stack{ int a, b; }st[101000]; int top, a[101000], b[101000], c1, c2, Res; char p[101000]; void ins(int a){ if (st[top].a == a)st[top].b++; else{ st[++top].a = a; st[top].b = 1; } } void init(){ while (top && !st[top].b)top--; } void Del1(){ st[top].b--; init(); } int Del2(){ return st[top--].b; } void Do(){ int i, ck, t; top = 0; scanf("%s", p); for (i = 0; p[i]; i++){ if (p[i] <= '2'){ ins(p[i] - '0'); continue; } if (p[i] == 'U'){ Del1(); continue; } if (p[i] == 'L')ck = 1; else ck = 2; if (st[top].a != ck){ Del1(); ins(ck); continue; } t = Del2(); Del1(); ins(ck); st[++top].a = 3 - ck; st[top].b = t; } } int main() { Do(); int i, c = 0, t; for (i = 1; i <= top; i++){ while (st[i].b--)a[++c1] = st[i].a; } Do(); for (i = 1; i <= top; i++){ while (st[i].b--)b[++c2] = st[i].a; } if (c1 > c2){ Res = c1 - c2; c1 = c2; } else Res = c2 - c1; for (i = 1; i <= c1; i++){ t = c * 2 - a[i] + b[i]; if (t > 3 || t < -3)break; c = t; } Res += (c1 + 1 - i) * 2; Res += c < 0 ? -c : c; printf("%d\n", Res); }
#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...