whats wrong with my logic?

Правка en1, от redsexx, 2026-03-24 16:42:07

https://mirror.codeforces.com/contest/2209/submission/367971487 367971487

hi everyone,

i tried solving this problem but my logic is failing on some cases. i'm not looking for a completely different solution, i just want to understand what is wrong with my reasoning.

my idea was the following.

first i find the color with the maximum count among r, g and b.

the reason is simple: the color with the largest frequency is the hardest one to place without breaking the constraints. so it feels natural to place it first. if we space the maximum element properly, it automatically creates room for the other two colors.

so if, for example, r is the largest, i start by placing all r at even indices (0, 2, 4, ...). this spreads them out and avoids adjacency.

then i start filling the odd indices with the second largest color, and after that with the third color.

so the structure becomes something like:

R _ R _ R _ R

and the blanks are filled with the other colors.

the idea was that this spacing should prevent: same colors being adjacent same colors appearing at distance 3

after building this temporary array, i convert it into the final string. if some elements of the third color are still left, i try to prepend or append them carefully so that adjacency is not violated.

i repeat the same logic for all three cases:

when r is maximum when g is maximum when b is maximum

so the main logic is:

place the most frequent color first (to spread it out) fill the gaps with the other colors attach any remaining characters carefully at the ends

i feel like the reasoning should work, but clearly something in this construction is wrong since some tests fail.

would appreciate if someone could point out where the logical flaw is.

thanks

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский redsexx 2026-03-24 16:42:07 1834 Initial revision (published)