#include <cstdio>
int n,cnt[100][100],inf=100000;
void run(int i,int j){
if(i==n-2 and j==n-2)return;
if(cnt[i][j]+1<cnt[i+1][j] and cnt[i+1][j]!=-1){
cnt[i+1][j]=cnt[i][j]+1;
run(i+1,j);
}
if(cnt[i][j]+1<cnt[i-1][j] and cnt[i-1][j]!=-1){
cnt[i-1][j]=cnt[i][j]+1;
run(i-1,j);
}
if(cnt[i][j]+1<cnt[i][j+1] and cnt[i][j+1]!=-1){
cnt[i][j+1]=cnt[i][j]+1;
run(i,j+1);
}
if(cnt[i][j]+1<cnt[i][j-1] and cnt[i][j-1]!=-1){
cnt[i][j-1]=cnt[i][j]+1;
run(i,j-1);
}
}
int main(){
scanf("%d\n",&n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(getchar_unlocked()=='.')cnt[i][j]=inf;
else cnt[i][j]=-1;
}
getchar_unlocked();
}
cnt[1][1]=1;
run(1,1);
if(cnt[n-2][n-2]==inf)puts("No solution!");
else printf("%d\n",cnt[n-2][n-2]);
}
通過檢測
通過檢測
通過檢測
通過檢測