elf_mcodek's blog

By elf_mcodek, history, 2 years ago, In English

Hello, I'm relatively new to cpp and codeforces. Ive been working the problem 1494A fora long time now, but I am still failing at some testcases. Could anyone just provide me a hint as to what I'm doing wrong. Any advices in general are also appreciated....Thank you in advance :)

Here's my solution : 144508668 to the problem: https://codeforces.com/problemset/problem/1494/A

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

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try to find a solution that is easiest to implement. Here it is to just try every possible combination. Every letter can be either '(' or ')' and there is 3 letters, thus $$$2^3 = 8$$$ combinations in total.

You don't need a stack to check if a string is an RBS with only one type of brackets. Just go over characters from left to right (or right to left) and maintain current balance in an integer variable. Increase balance on opening brackets and decrease it on closing brackets. If balance ever gets negative or is not exactly zero after processing entire string it is not an RBS.

Sometimes it's helpful to search for quick ways to do something instead of implementing it yourself. It turns out there is a function std::replace() that can help us replace every occurrence of a character in a string with other character in one line of code.

https://codeforces.com/contest/1494/submission/144594509