#include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; char str[2005][2005]; int dx[2]={1,0}; int dy[2]={0,1}; ll dp[2005][2005]; int main(int argc, char* argv[]) { int h,w; scanf("%d%d", &h, &w); int i,j,k; for(i=0; i=h || j2>=w) continue; int add=(str[i2][j2]=='k'? i2+j2+1: 1); dp[i2][j2]=MIN(dp[i2][j2],dp[i][j]+add); } } } printf("%lld\n", dp[h-1][w-1]); return 0; }