/* -*- coding: utf-8 -*- * * 971.cc: No.971 いたずらっ子 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_H = 1000; const int MAX_W = 1000; const int INF = 1 << 30; /* typedef */ /* global variables */ char fs[MAX_H][MAX_W + 4]; int ds[MAX_H][MAX_W]; /* subroutines */ inline void setmin(int &a, int b) { if (a > b) a = b; } /* main */ int main() { int h, w; scanf("%d%d", &h, &w); for (int y = 0; y < h; y++) { scanf("%s", fs[y]); fill(ds[y], ds[y] + w, INF); } ds[0][0] = 0; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { int vd = ds[y][x] + 1; if (fs[y][x] == 'k') vd += y + x; if (y + 1 < h) setmin(ds[y + 1][x], vd); if (x + 1 < w) setmin(ds[y][x + 1], vd); } printf("%d\n", ds[h - 1][w - 1]); return 0; }