271 - Simply Syntax
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 271 - WA
Print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 15
- Joined: Fri May 30, 2014 12:09 am
Re: 271 - Simply Syntax
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
Accepted output:
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
Code: Select all
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO