#include #include #include #define ll long long using namespace std; struct ST { int y, x; int dist; int tm; ST():dist(-1),tm(-1){} ST(int y, int x, int dist, int tm):y(y),x(x),dist(dist),tm(tm){} }; bool operator<(const ST& a, const ST& b){ if(a.tm == b.tm) return a.dist < b.dist; return a.tm < b.tm; } bool operator>(const ST& a, const ST& b){ if(a.tm == b.tm) return a.dist > b.dist; return a.tm > b.tm; } ST dp[2005][2005]; int main(){ int H, W; cin >> H >> W; vector field; for(int i=0; i> s; field.push_back(s); } priority_queue,greater> que; que.push(ST(0, 0, 0, 0)); while(!que.empty()){ ST st = que.top(); que.pop(); if(dp[st.y][st.x].tm == -1 || st < dp[st.y][st.x]){ dp[st.y][st.x] = st; if(st.x+1