First of all, let me feed you all the details:
- Problem: 1008A
- Hack #: 468003
- Submission: http://mirror.codeforces.com/contest/1008/submission/40270051
- Input: "ae"
- Output(desirable): NO
- Output(obtained): YES
In the above-mentioned solution, there is a block of logic as mentioned below:
if(!flag['a' - *(s.end() - 1)] && *(s.end() - 1) != 'n')
{
cout<<"NO"<<endl;
return 0;
}
Here, we can see that first condition in the if statement is wrong. So I targeted that statement for my hack with the input "ae". Here we can see that the program will try to access flag['a'-'e'] which doesn't exist and hence should return false and should go inside the if block and print NO.
But as per the verdict of the hack, output was YES which is quite contradictory. Also, the same solution yielded the desirable output (i.e NO) on main test 23 with the similar kind of input.
Thus, I am requesting testers demon1999 and winger to kindly look into this matter.
Thank you.
So, his trying to access flag[-4].
the program will try to access flag['a'-'e'] which doesn't exist and hence should return false
That statement is false. It's undefined behaviour, it can return either true or false (or even segmentation fault) depending of what memory is currently goes before array flag[] on your machine. You just was unlucky.
Check this code, for example. Most likely it will print "I'm right" on your machine, but you can't be sure what will happen on the other machines, including CF.
I know that the answer can be either way. But does it imply that I am wrong and should get -50 as penalty points for the unsuccessful hack.
Ofcourse you should. You statement is "His solution won't work on this test on CF machine", while his solution perfectly works, which means your hack is unsuccessful. You simply shouldn't do hacks based on undefined behavior unless you sure it certainly won't work on given CF machine and given compiler — that what hack is for.
There is no logic way to determine undefined behavior and let contestant make special circumstances when this solution won't work and let him hack it.