結果
問題 |
No.971 いたずらっ子
|
ユーザー |
|
提出日時 | 2020-04-04 04:23:55 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,492 bytes |
コンパイル時間 | 1,951 ms |
コンパイル使用メモリ | 77,712 KB |
実行使用メモリ | 77,500 KB |
最終ジャッジ日時 | 2024-07-03 06:51:34 |
合計ジャッジ時間 | 13,805 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 7 WA * 14 |
ソースコード
import java.util.*; public class Main { static int INF=1000000; 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]*2+2){ dist[i][j]=dist[i-1][j]*2+2; change=true; } } } if(i!=H-1){ 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]*2+2){ dist[i][j]=dist[i+1][j]*2+2; 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]*2+2){ dist[i][j]=dist[i][j-1]*2+2; change=true; } } } if(j!=W-1){ 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]*2+2){ dist[i][j]=dist[i][j+1]*2+2; change=true; } } } } } if(!change){ break; } } System.out.println(dist[H-1][W-1]); } }