import java.util.*; public class Main { static int INF=1000000; public static int min2(int a,int b){ return (adist[i-1][j]+1){ dist[i][j]=dist[i-1][j]+1; change=true; } }else{ if(dist[i][j]>dist[i-1][j]+i+j+1){ dist[i][j]=dist[i-1][j]+i+j+1; change=true; } } } if(j!=0){ if(map[i][j]==0){ if(dist[i][j]>dist[i][j-1]+1){ dist[i][j]=dist[i][j-1]+1; change=true; } }else{ if(dist[i][j]>dist[i][j-1]+i+j+1){ dist[i][j]=dist[i][j-1]+i+j+1; change=true; } } } } } if(!change){ break; } } System.out.println(dist[H-1][W-1]); } }