redsexx's blog

By redsexx, history, 3 weeks ago, In English

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

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By redsexx, history, 6 weeks ago, In English

https://mirror.codeforces.com/contest/2171/submission/365464004

My idea is simple. Divide the array into maximal strictly increasing subarrays.

Inside each subarray, connect adjacent elements with undirected edges.

For every subarray i starting from the second one, connect the last element of that subarray to the minimum element that appeared before it (I maintain a running minimum from previous parts).

After building the graph, I run DFS to check if the graph becomes connected.

If it is connected, I print "yes" and output the tree.

My code builds the graph exactly like this, but it gives wrong answers on some test.

So I want to know:

Is the logic itself incorrect, or is there likely an implementation mistake?

If the logic is wrong, where exactly does this idea fail?

Any hints would help.

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By redsexx, history, 9 months ago, In English

Hello, I’m getting Wrong Answer on test 2 for problem 2084C and could really use your insight. In my solution I use a variable samesame to count how many positions i satisfy a[i] == b[i]. If n is odd and samesame != 1, I immediately print -1; if n is even and samesame != 0, I also print -1. Otherwise, I perform a brute‑force sequence of swaps to try to make a and b reverse of each other—but I still can’t even pass test 2. Any idea what I’m missing?

Problem link: https://mirror.codeforces.com/contest/2084/problem/C My submission: https://mirror.codeforces.com/contest/2084/submission/328626310

Thank you in advance

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it