結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 633 ms
67,960 KB
testcase_01 AC 568 ms
69,672 KB
testcase_02 AC 591 ms
64,016 KB
testcase_03 AC 616 ms
68,420 KB
testcase_04 AC 620 ms
69,748 KB
testcase_05 AC 623 ms
69,352 KB
testcase_06 AC 559 ms
65,004 KB
testcase_07 AC 155 ms
42,228 KB
testcase_08 AC 442 ms
52,668 KB
testcase_09 AC 388 ms
52,476 KB
testcase_10 AC 152 ms
42,088 KB
testcase_11 AC 111 ms
41,160 KB
testcase_12 AC 111 ms
41,336 KB
testcase_13 AC 120 ms
41,220 KB
testcase_14 AC 208 ms
42,528 KB
testcase_15 AC 118 ms
41,280 KB
testcase_16 AC 122 ms
41,840 KB
testcase_17 AC 107 ms
41,424 KB
testcase_18 AC 111 ms
41,164 KB
testcase_19 AC 106 ms
40,920 KB
testcase_20 AC 100 ms
39,960 KB
testcase_21 AC 103 ms
40,444 KB
testcase_22 AC 104 ms
40,260 KB
testcase_23 AC 111 ms
41,128 KB
testcase_24 AC 110 ms
41,412 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);
	}
	
	final long MOD=998244353;
	
	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