GARGOYLE - PELT2019 Probable Verdict Error

LINK TO MY SOLUTION

It got WA verdict during the contest last week but the similar solution is mentioned in the editorial.
LINK TO THE EDITORIAL

When I commented on the same and posted the link to my solution there, the author @panik replied ->

" I am looking into your solution although its giving the correct ans on codechef compiler on the TC on which your solution is showing wrong, i am looking into it."

On codeforces posts, someone suggested with possible test cases and errors, it’s giving correct answer on every such case.

Till now, there is no reply from the Author.

Moral of the story : Can anyone please let me know what’s actually my mistake in the code?

1 Like

You were given A reply on codeforces right, that using getline might have caused an issue. Is that point not valid.

I think I found the problem. It is with getline.

I submitted this solution first: solution_1.
Why did I use cin.ignore() inside the loop? Because the sample test case contains a new line after every string. So I thought I need to ignore it as well. Did not work though.

Then I submitted this: solution_2.
This time I assumed that there are no additional new lines after every string. Something like:


3
T T T
T F F
F F F

Again did not work.

Then I submitted this: solution_3.
This time I assumed that the test cases are somewhat like:


3
[\n]
[\n]

T T T
F F F
T T F

And hence I used cin.ignore() twice before entering the loop. And hurrah! This one passed.

Just wanted to add, using getline and cin.ignore() is just way too cumbersome, so I try to avoid them as much as possible.

Your actual solution had some issues when I tried to input the sample test cases as:
./program < in .

Hi @arjitkansal ,

The issue with your solution is that, its input method is OS dependent. newline character can be different for different OS’es, eg- its just \n for unix and \r\n (2 characters) for Windows. It is always urged in the FAQ’s to write code which is independent of such differences among OS’es. The best way to do that is, use a dummy getline(cin,s); to take that extra newline.

I think now you can explain why 2 cin.ignore();'s fixed the issue.

1 Like

Thanks @vijju123 This is the first time I encountered this problem. But just one thing, many times before I’ve used this method for similar inputs on codechef and never got WA. And also this code was running successfully on codechef ide. Why was that then?

The person who replied there gave a test case in totally different format, which confused me. I tried to clarify it there as well but he didn’t reply.

//