1 / 2
Jul 2022

Can anyone tell me for which test case I am getting WA?
Problem Link : CATM11

  #include <bits/stdc++.h>
using namespace std;

void CatMove(int &ci, int &cj, int mi, int mj) { // cat moves closer to mouse
    if (mi > ci)
        ci++;
    else if (mi < ci)
        ci--;
    else if (mj > cj)
        cj++;
    else if (mj < cj)
        cj--;
}

void MouseMove(int &mi, int &mj, int k) { // mouse moves upwards,downwards, left or right
    if (k == 0) mi--;
    if (k == 1) mi++;
    if (k == 2) mj--;
    if (k == 3) mj++;
}

int main() {
    int n, m;
    cin >> n >> m;
    int tc;
    cin >> tc;
    while (tc--) {
        int mi, mj, c1i, c1j, c2i, c2j;
        cin >> mi >> mj >> c1i >> c1j >> c2i >> c2j;
        bool possible = false;
        for (int k = 0; k < 4; k++) { // checks if the mouse can pass the grid by moving straight in any of the four directions
            int C1i = c1i, C1j = c1j, C2i = c2i, C2j = c2j, Mi = mi, Mj = mj;// temporaray variables for calculation for the iteration
            while (1) {
                if ((C1i == Mi && C1j == Mj) || (C2i == Mi && C2j == Mj)) {
                    break;
                }
                MouseMove(Mi, Mj, k);
                if (Mi < 1 || Mj < 1 || Mi > n || Mj > m) {
                    possible = true;
                    break;
                }
                CatMove(C1i, C1j, Mi, Mj);
                CatMove(C2i, C2j, Mi, Mj);
            }
            if (possible) break;
        }
        if (possible)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}
  • created

    Jul '22
  • last reply

    Jul '22
  • 1

    reply

  • 605

    views

  • 2

    users

  • 1

    like

  • 1

    link

Here’s one where my AC code gives a different answer to yours:

10 10
1
4 6 2 8 5 5