RRCODE - Editorial

after seeing this editorial, i feel stupid. good question setter. thumps up for u

1 Like

changed. thanks :slight_smile:

s = raw_input().strip() worked…whats the use of strip()??

@r3gz3n it removes any whitespace from the end or beginning of the string,
in this case the input

But the question says " It is guaranteed that there will be no whitespaces before or after Operator."??

Such problems are so necessary to remind us that cases determination is an important part however easy the problem be … good thinking …

@sobhagya - thanks for input… but could not get your point. if I am continuing to next test case when k==0 by simply printing the given ‘ans’ and not reading the array/operator, then why should it at all give ‘Time Limit Exceed’ problem. in fact for k==0, this reduces the task of reading the array unnecessarily… would you mind explaining a bit ?

@sayantancs Try this input:

2
5 0 1
1000000000 2 3 4 5
XOR
2 2 2
3 3
AND

If you do not care to read off the array in the first test case, then you take the value of n for the second test case as 10^9, k as 2 and ans as 3, and proceed with a loop that runs 10^9 times to read the array that actually does not exist.

I think, now, what @sobhagya tried to say has become clear.

The point is, you need to simply read the array off, to get to the next input. (This is necessary!!)

3 Likes

I too got frustrated for not handling k==0 case.
I got 2 WA for that.

@tijoforyou - okk. got it… thanks… largely overlooked that fact :frowning:

gets is deprecated. You shave have taken input by

 
scanf("%s", str);

Can someone tell me the problem in this solution:
http://www.codechef.com/viewsolution/2727952
Been stuck for too long.
Tried removing one getchar() but that didn’t work either.

last reply to this topic was over 9 years ago. Your reply will bump the topic to the top of its list and notify anyone previously involved in the conversation.

Are you sure you want to continue this old conversat