```
void solveNQueens_iter(int *solution,int row,int n,vector<vector<string> >&result){
int i;
int j;
if( row == n ){
vector<string>temp;
temp.clear();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if( solution[i] == j){
temp.push_back("Q");
}
else{
temp.push_back(".");
}
}
}
//cnt++;
result.push_back(temp);
return;
}
int col ;
int check;
int next_row;
for(col=0;col<n;col++){
next_row = 1;
for(check=0;check<row;check++){
if( (solution[check] == col) ||
(abs(row-check) == abs(col-solution[check])) ){
next_row = 0;
break;
}
}
if(next_row){
solution[row] = col;
solveNQueens_iter(solution,row+1,n,result);
}
}
}
vector<vector<string> > solveNQueens(int n){
vector<vector<string> > result;
int solution[n];
int i;
for(i=0;i<n;i++){
solution[i] = -1;
}
solveNQueens_iter(solution,0,n,result);
return result;
}
```

This is my code,but it report output limit exceed.

How can I modify it?

In my machine,it cost too long when N is 16.