leminhan.169's blog

By leminhan.169, history, 4 years ago, In English

E1. Erase and Extend (Easy Version) https://mirror.codeforces.com/problemset/problem/1537/E1

"We claim that it is optimal to choose a prefix of the string, then duplicate it until we have a length bigger than k, then delete the excess elements." (solution)

I don't know how to prove that we only need to append the prefix and duplicate multiple times then we can obtain the lexicographically smallest string. Even many people solved the problem intuitively but for me it doesn't work that way. I try to prove it instead accept it. However, I was stuck so long and frustrated at it. Can someone help me prove it please?

Full text and comments »

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

By leminhan.169, history, 4 years ago, In English

1272E — Nearest Opposite Parity https://mirror.codeforces.com/problemset/problem/1272/E

The problem asks us to find the shorted distant between two number with different parity in an array. In this problem, we should create an inverted graph instead of normal graph. In another word, graph[u].pb(v) meaning that vertex u is reachable from vertex v. I don't understand the idea here even after reading the discussion and solutions again multiples time. Can someone give me an insight for this? Thank you so much.

I just found a similar article at GfG explaining about this problem. However, they don't mention specifically the reason using inverted graph.

Full text and comments »

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