最后一个点 WA 了
#include <bits/stdc++.h>
//#define int long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++
namespace FIO{static char buf[1<<20],*p1=buf,*p2=buf;inline int rd(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();return x*f;}inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');}inline void pt(int x){if(!x)putchar('0');else{int s[20],t;for(t=0;x;x/=10)s[t++]=x%10;while(t)putchar(s[--t]^48);}putchar('\n');}}using namespace FIO;
namespace zty
{
const int N = 501;
const int dx[] = {-1, -1, 1, 1}, dy[] = {-1, 1, 1, -1};
bool m1;
int n, m, st[N][N];
bool a[N][N][4]; // 0->左上 / 1->右上 / 2->右下 / 3->左下
char ch;
struct G
{
int x, y, t;
};
bool m2;
void bfs()
{
G tmp = {1, 1, 0};
deque<G> q;
q.push_back(tmp);
st[1][1] = 0;
while (q.size())
{
G t = q.front();q.pop_front();
int x = t.x, y = t.y;
//cout << x << " " << y << " " << t.t << endl;
if (x == n + 1 && y == m + 1)
return cout << t.t << endl, void();
rep(i, 0, 3)
{
int xx = x + dx[i], yy = y + dy[i];
if (xx < 1 || xx > n + 1 || yy < 1 || yy > m + 1) continue;
if (a[x][y][i] && st[xx][yy] <= t.t + 1 || !a[x][y][i] && st[xx][yy] <= t.t) continue;
if (a[x][y][i]) tmp = {xx, yy, t.t + 1}, q.push_back(tmp), st[xx][yy] = t.t + 1;
else tmp = {xx, yy, t.t}, q.push_front(tmp), st[xx][yy] = t.t;
//cout << "(" << x << "," << y << ") -> (" << xx << "," << yy << "): " << t.t << " -> " << tmp.t << endl;
}
}
return cout << "NO SOLUTION" << endl, void();
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//cout << fixed << setprecision(3) << (&m2 - &m1) / 1024.0 / 1024 << endl;
memset(st, 0x3f, sizeof st);
cin >> n >> m;
rep(i, 1, n)
rep(j, 1, m)
{
cin >> ch;
if (ch == '/')
a[i][j][2] = 1, a[i + 1][j + 1][0] = 1, a[i + 1][j][1] = 0, a[i][j + 1][3] = 0;
else
a[i][j][2] = 0, a[i + 1][j + 1][0] = 0, a[i + 1][j][1] = 1, a[i][j + 1][3] = 1;
}
bfs();
return 0;
}
}
signed main()
{
//freopen(".in", "r", stdin), freopen(".out", "w", stdout);
zty::main();
}