SHOOTING - COOK49 WA

I used naive recursion because the constraints were small.
My code is:
So x1, y1 indicates the position upto which we have checked the lasers. The function will copy the grid to a1,a2 and a3. In a1, I killed all enemies in upper direction and recursively called the function again. In a2, I killed all the ones in left direction, and in a3, I killed the ones in right direction. Can someone please help! It sucks that I am getting WA.

#include<iostream>
#include<vector>
#include<string>
using namespace std;

bool proc(int x1,int y1,vector<string> a,int n,int m);

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
              int n,m;
              cin >> n >> m;
              vector<string> a;
              a.resize(n);
              for(int i = 0;i < n;i++)
                              cin >> a[i];
              bool c = proc(0,0,a,n,m);
              if(c == true) cout << "Possible" << endl;
              else cout << "Impossible" << endl;
    }
    return 0;
}

bool proc(int x1, int y1,vector<string> a,int n,int m) {
     int x,y;
     for(x = x1;x < n;x++)
             for(y = y1;y < m;y++)
                   if(a[x][y] == 'L') goto label1;
     if(x == n || y == m)
     {
          for(int i  = 0;i < n;i++)
                  for(int j = 0;j < m;j++)
                          if(a[i][j] == 'E') return false;
          return true;
     }
     label1: ;
     vector<string> a1;
     vector<string> a2;
     vector<string> a3;
     a1.resize(n);
     a2.resize(n);
     a3.resize(n);
     for(int i = 0;i < n;i++)
                      a1[i] = a[i];
     for(int i = 0;i < n;i++)
                      a2[i] = a[i];
     for(int i = 0;i < n;i++)
                      a3[i] = a[i];
     
     for(int i = x;i >= 0;i--)
             if(a1[i][y] == 'E') a1[i][y] = '.';
     a1[x][y] = '.';
     bool l = proc(x,y,a1,n,m);
     if(l == true) return true;
     
     for(int i = y;i >= 0;i--)
             if(a2[x][i] == 'E') a2[x][i] = '.';
     a2[x][y] = '.';
     bool k = proc(x,y,a2,n,m);
     if(k == true) return true;
     
     for(int i = y;i < m;i++)
             if(a3[x][i] == 'E') a3[x][i] = '.';
     a3[x][y] = '.';
     bool d = proc(x,y,a3,n,m);
     if(d == true) return true;
     
     return false;
}
2 Likes

My approach is also similar,I am also getting wa.
http://www.codechef.com/viewsolution/4662188

1 Like

I am as well tried everything and still getting wrong answer(Even though the examples I get the right answer). I believe that the conditions are not set properly in the problem. I mean, to get Possible do you have to destroyed every enemy you got in your lasers way or you just need to have lasers at the end of the shooting? Because if at the beginning the test gives you … LL there is noting to kill like the statement tells you, so it is Impossible. But if you think that in the end after shooting you just have L’s so you win thus it is Possible. Another case is . -> Impossible, or L -> Impossible because there’s noting to kill or could be Possible because it’s a laser at the end. Another case E --> must be impossible, there’s no laser to shoot with. I leave you my code, I use the statement ‘Find out whether it’s possible to kill all the enemies on the grid’. If there is no way to kill everything or anything at all I print Impossible, Possible otherwise.
https://www.codechef.com/viewsolution/22893519