結果

問題 No.971 いたずらっ子
ユーザー Mishan5055Mishan5055
提出日時 2020-04-04 04:48:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,405 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 73,876 KB
実行使用メモリ 87,480 KB
最終ジャッジ日時 2023-09-16 05:22:00
合計ジャッジ時間 11,479 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 562 ms
86,952 KB
testcase_06 AC 533 ms
84,716 KB
testcase_07 AC 171 ms
56,352 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 161 ms
56,120 KB
testcase_11 AC 123 ms
55,616 KB
testcase_12 AC 122 ms
55,916 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 138 ms
55,716 KB
testcase_17 AC 123 ms
55,780 KB
testcase_18 AC 123 ms
55,592 KB
testcase_19 AC 126 ms
55,760 KB
testcase_20 AC 121 ms
55,680 KB
testcase_21 AC 123 ms
55,528 KB
testcase_22 AC 125 ms
55,704 KB
testcase_23 AC 122 ms
54,420 KB
testcase_24 AC 123 ms
55,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]+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]);
    }
}
0