結果
問題 | No.971 いたずらっ子 |
ユーザー | Mishan5055 |
提出日時 | 2020-04-04 04:50:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 612 ms / 2,000 ms |
コード長 | 2,408 bytes |
コンパイル時間 | 1,938 ms |
コンパイル使用メモリ | 73,788 KB |
実行使用メモリ | 86,648 KB |
最終ジャッジ日時 | 2023-08-07 08:06:22 |
合計ジャッジ時間 | 11,137 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 612 ms
86,252 KB |
testcase_01 | AC | 612 ms
86,536 KB |
testcase_02 | AC | 581 ms
84,736 KB |
testcase_03 | AC | 565 ms
86,648 KB |
testcase_04 | AC | 560 ms
86,556 KB |
testcase_05 | AC | 558 ms
86,228 KB |
testcase_06 | AC | 525 ms
85,088 KB |
testcase_07 | AC | 167 ms
56,196 KB |
testcase_08 | AC | 448 ms
64,388 KB |
testcase_09 | AC | 461 ms
65,112 KB |
testcase_10 | AC | 163 ms
56,224 KB |
testcase_11 | AC | 122 ms
55,640 KB |
testcase_12 | AC | 122 ms
55,892 KB |
testcase_13 | AC | 129 ms
55,592 KB |
testcase_14 | AC | 169 ms
56,248 KB |
testcase_15 | AC | 127 ms
53,796 KB |
testcase_16 | AC | 131 ms
55,380 KB |
testcase_17 | AC | 119 ms
55,592 KB |
testcase_18 | AC | 120 ms
55,856 KB |
testcase_19 | AC | 119 ms
55,688 KB |
testcase_20 | AC | 119 ms
56,016 KB |
testcase_21 | AC | 122 ms
55,524 KB |
testcase_22 | AC | 124 ms
56,136 KB |
testcase_23 | AC | 120 ms
56,268 KB |
testcase_24 | AC | 119 ms
55,652 KB |
ソースコード
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]); } }