harshvasoya008's blog

By harshvasoya008, 6 years ago, In English

First of all, let me feed you all the details:

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.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
6 years ago, # |
Rev. 11   Vote: I like it +32 Vote: I do not like it

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.

bool model[4];
bool flag[26];
int main()
{
    model[0] = true;
    if (flag[-4])
        cout << "I'm right" << endl;
    else
        cout << "No!!" << endl;
}

  • »
    »
    6 years ago, # ^ |
      Vote: I like it -30 Vote: I do not like it

    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.

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 3   Vote: I like it +18 Vote: I do not like it

      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.