Solution to 3142C Ternary XOR
Difference between en1 and en2, changed 18 character(s)
My first solved-problem on Codeforces.↵

It's really an easy problem.↵

As we know, if you want to make the a and b as small as possible, they must only contain digits 0 and 1.↵

So, we have the thinking in the following:↵

1. if the digit of x[i] is 2: we try to make a[i] and b[i] both 1.↵
2. if the digit of x[i] is 0: we try to make a[i] and b[i] both 0.↵
3. if the digit of x[i] is 1: either a[i] or b[i] would be 1. We'll make a[i] 1 because it is no difference if we make b[i] 1.↵

However, if we make a[i] 1, the number a must be larger than b as a fact.↵

So, we would not want to make array a still bigger. So after we make a[i] 1, we have different thinking:↵

1. if the digit of x[i] is 2: we make a[i] 0 and b[i] 2.↵
2. if the digit of x[i] is 0: we make a[i] and b[i] both 0.↵
3. if the digit of x[i] is 1: we make a[i] 0 and b[i] 1.↵

That's all. We'll discover that after we make a[i] 1, a does not increase anymore, but b is increasing, however it will never be bigger than a.↵

Thanks for reading, hope that'll help you!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English pengyule 2020-05-29 10:58:07 18
en1 English pengyule 2020-05-29 05:49:01 1058 Initial revision (published)