結果
問題 | No.971 いたずらっ子 |
ユーザー |
|
提出日時 | 2020-04-04 04:50:11 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 671 ms / 2,000 ms |
コード長 | 2,408 bytes |
コンパイル時間 | 2,195 ms |
コンパイル使用メモリ | 77,384 KB |
実行使用メモリ | 74,608 KB |
最終ジャッジ日時 | 2024-11-07 11:44:03 |
合計ジャッジ時間 | 11,916 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
import java.util.*; public class Main { static int INF=1000000000; public static int min2(int a,int b){ return (a<b)?a:b; } public static boolean mining2(int a,int b){ if(a<b){ a=b; return true; }else{ return false; } } public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); int H=sc.nextInt(); int W=sc.nextInt(); int[][] map=new int[H][W]; for(int i=0;i<H;i++){ String tmp=sc.next(); for(int j=0;j<W;j++){ if(tmp.charAt(j)=='.'){ map[i][j]=0; }else{ map[i][j]=1; } } } int[][] dist=new int[H][W]; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ dist[i][j]=INF; } } dist[0][0]=0; boolean change=true; while(change){ change=false; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(i!=0){ if(map[i][j]==0){ if(dist[i][j]>dist[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]); } }