結果

問題 No.971 いたずらっ子
ユーザー 37zigen37zigen
提出日時 2020-03-28 02:43:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 649 ms / 2,000 ms
コード長 3,107 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 79,268 KB
実行使用メモリ 68,924 KB
最終ジャッジ日時 2024-04-25 02:12:30
合計ジャッジ時間 11,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 626 ms
68,828 KB
testcase_01 AC 649 ms
68,840 KB
testcase_02 AC 583 ms
64,136 KB
testcase_03 AC 533 ms
67,948 KB
testcase_04 AC 614 ms
68,924 KB
testcase_05 AC 584 ms
68,208 KB
testcase_06 AC 568 ms
64,520 KB
testcase_07 AC 154 ms
42,124 KB
testcase_08 AC 376 ms
51,612 KB
testcase_09 AC 419 ms
52,464 KB
testcase_10 AC 131 ms
41,664 KB
testcase_11 AC 111 ms
41,300 KB
testcase_12 AC 111 ms
41,344 KB
testcase_13 AC 115 ms
40,996 KB
testcase_14 AC 190 ms
43,208 KB
testcase_15 AC 128 ms
40,512 KB
testcase_16 AC 125 ms
41,432 KB
testcase_17 AC 113 ms
41,392 KB
testcase_18 AC 108 ms
39,960 KB
testcase_19 AC 106 ms
41,096 KB
testcase_20 AC 110 ms
41,072 KB
testcase_21 AC 111 ms
40,928 KB
testcase_22 AC 110 ms
40,340 KB
testcase_23 AC 120 ms
41,348 KB
testcase_24 AC 114 ms
40,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		char[][] a=new char[H][W];
		for(int i=0;i<H;++i) {
			a[i]=sc.next().toCharArray();
		}
		int[][] dp=new int[H][W];
		int INF=Integer.MAX_VALUE/3;
		for(int i=0;i<H;++i)for(int j=0;j<W;++j)dp[i][j]=INF;
		dp[0][0]=0;
		for(int sum=1;sum<=H-1+W-1;++sum) {
		for(int i=0;i<H;++i) {
			int j=sum-i;
			if(j<0||j>=W)continue;
			if(a[i][j]=='.') {
					dp[i][j]=1+Math.min((i>0?dp[i-1][j]:INF), (j>0?dp[i][j-1]:INF));
				}else {
					dp[i][j]=i+j+1+Math.min((i>0?dp[i-1][j]:INF), (j>0?dp[i][j-1]:INF));
				}
			}
		}
		System.out.println(dp[H-1][W-1]);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
	
	
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
}
0