Kindly find the error and modify the code

Your logic is correct.But there are many errors in your code.Your while loop is not correct,also n>1000 so you cannot define an array of 1000 elements initially either use vector or array having sufficient size for all testcase.In your canplace function you have used lowcow instead of lastcow.
I have edited your code it is working fine.

If you think your doubt is resolve then please mark it as resolved and give your feedback:)