#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; template struct Graph { struct edge { int to; T cost; }; int N; vector> G; vector dist; vector prever; Graph(int n) { init(n); } T inf() { if (is_same_v) return 1e9; else return 1e18; } T zero() { return T(0); } void init(int n) { N = n; G.resize(N); dist.resize(N, inf()); } void add_edge(int s, int t, T cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(int s) { rep(i, 0, N) dist[i] = inf(); prever = vector(N, -1); dist[s] = zero(); priority_queue, vector>, greater>> q; q.push({zero(), s}); while (!q.empty()) { int now; T nowdist; tie(nowdist, now) = q.top(); q.pop(); if (dist[now] < nowdist) continue; for (auto e : G[now]) { T nextdist = nowdist + e.cost; // 次の頂点への距離 if (dist[e.to] > nextdist) { prever[e.to] = now; dist[e.to] = nextdist; q.push({dist[e.to], e.to}); } } } } vector get_path(int t) { // tへの最短路構築 if (dist[t] >= inf()) return {-1}; vector path; for (; t != -1; t = prever[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } }; int main() { int h, w; cin >> h >> w; vector s(h); rep(i, 0, h) cin >> s[i]; Graph gr(h * w); rep(i, 0, h) rep(j, 0, w) { if (s[i][j] == '#') continue; rep(k, 0, 4) { int ni = i + "1012"[k] - '1'; int nj = j + "2101"[k] - '1'; if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue; if (s[ni][nj] == '#') continue; ll cost = 0; if (i != ni) cost += 1; if (j != nj) cost += 1e9; gr.add_edge(i * w + j, ni * w + nj, cost); } } gr.dijkstra(0); ll ans = gr.dist[h * w - 1]; if (ans >= gr.inf()) { cout << "No\n"; return 0; } cout << "Yes\n"; ll x = ans / (ll)1e9; ll y = ans % (ll)1e9; cout << x << ' ' << y << '\n'; }