271 - Simply Syntax

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 271 - WA

Post by brianfry713 »

Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
TryCatchMe
New poster
Posts: 15
Joined: Fri May 30, 2014 12:09 am

Re: 271 - Simply Syntax

Post by TryCatchMe »

Hello all,

First of all, you can do this problem without recursion. It is solve-able using recursion, but definitely not necessary. A recursive solution may not run in time. I will give you all a hint: use a stack! Also, if you think about the problem you will realize you just need a for loop with no recursive calls.

Secondly, people must understand that you most likely do NOT need to be dynamically allocating memory if using C/C++. Almost every problem statement will tell you the bounds of the problem and if not you can guess-timate it. Dynamically allocating memory is going to slow you down big time. In the hundreds of problems I have solved I have rarely used dynamic memory allocation (malloc in C, new in C++). Of course the underlying STL data structures may be doing this but I avoid it at all costs.

Third, I have some sample I/O for anyone who is struggling with this problem:

Input

Code: Select all

NNNNNNCst
CNNCstt
CNNNNNNNNCstv
CCNNNNNNNNCstvp
CCNNNNNNNNCstvv
CCNNNCsttt
CCNNNCpqrs
CNst
CCCsttt
s
st
Nst
Csts
CCCstt
NNCssst
sN
st

s
sCst
NNNsCstp
Accepted output:

Code: Select all

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
Post Reply

Return to “Volume 2 (200-299)”