class Solution {
public:
vector<vector<string>> res;
int* x;
void helper(int t,int n)
{
if(t>n-1)
{
vector<string> a;
for(int i=0;i<=n-1;i++)
{
string str(n,'.');
str[x[i]]='Q';
a.push_back(str);
cout<<str<<endl;
}
res.push_back(a);
}
else
{
for(int i=0;i<=n-1;i++)
{
x[t]=i;
bool b=true;
for(int j=0;j<=t-1;j++)
if(abs(t-j)==abs(x[t]-x[j])||x[t]==x[j])
b=false;
if(b)
helper(t+1,n);
}
}
}
vector<vector<string>> solveNQueens(int n) {
x=(int*)malloc(sizeof(int)*n);
helper(0, n);
return res;
}
};