Thanks for your inputs @narbej
Iâve seen most already existing threads on this topic and went through all comments on problem description. I was careful of all mentioned corner cases but canât make out the error in my code.
~
This is what all I did to debug:
After making the changes you mentioned I was still getting TLE.
After that, I tried generating a faulty testcase following your generator-program method and found that I was passing the visited vector of bool vectors by value and not by reference which was causing the TLEs in some cases.
Then I corrected that and still was getting TLE at a case.
I successfully figured out a TLE test case generated by the generator-program but am unable to make out my error in code which is making it TLEâŚ
My latest code is:
Got AC!
And one failing TLE test case generator is:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n = 4; // up to 1000
//cin >> n; //or use this
cout << n << '\n';
/*
for (int i = 0; i < n; ++i){
for (int j = 0; j < n; ++j)
cout << '.';
cout << '\n';
}
*/
for (int j=0; j<n; j++)
cout<<'.';
cout<<'\n';
cout<<'#';
for (int j=0; j<n-1; j++)
cout<<'.';
cout<<'\n';
for (int i = 2; i < n-2; ++i){
for (int j = 0; j < n; ++j)
cout << '.';
cout << '\n';
}
cout<<'.';
for (int j=0; j<n-1; j++)
cout<<'#';
cout<<'\n';
for (int j=0; j<n; j++)
cout<<'.';
cout<<'\n';
}
I noticed that it is passing when n=4 in the test-generator.
Will making the queue on heap help? But there is no Stack Buffer overflow error⌠the loop simply seems to go on and doesnât finish in time for n=1000.