結果

問題 No.2708 Jewel holder
ユーザー tentententen
提出日時 2024-04-01 15:46:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 3,098 bytes
コンパイル時間 2,569 ms
コンパイル使用メモリ 80,264 KB
実行使用メモリ 54,012 KB
最終ジャッジ日時 2024-04-01 15:46:42
合計ジャッジ時間 4,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,992 KB
testcase_01 AC 52 ms
54,000 KB
testcase_02 AC 52 ms
53,980 KB
testcase_03 AC 53 ms
53,996 KB
testcase_04 AC 52 ms
53,980 KB
testcase_05 AC 55 ms
54,012 KB
testcase_06 AC 53 ms
53,988 KB
testcase_07 AC 53 ms
53,988 KB
testcase_08 AC 51 ms
53,992 KB
testcase_09 AC 52 ms
54,000 KB
testcase_10 AC 57 ms
54,000 KB
testcase_11 AC 52 ms
53,992 KB
testcase_12 AC 53 ms
53,980 KB
testcase_13 AC 53 ms
53,984 KB
testcase_14 AC 53 ms
53,980 KB
testcase_15 AC 53 ms
53,964 KB
testcase_16 AC 53 ms
53,988 KB
testcase_17 AC 58 ms
54,004 KB
testcase_18 AC 52 ms
53,996 KB
testcase_19 AC 52 ms
53,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] field = new char[h][];
        List<List<Map<Integer, Integer>>> dp = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            field[i] = sc.next().toCharArray();
            dp.add(new ArrayList<>());
            for (int j = 0; j < w; j++) {
                dp.get(i).add(new HashMap<>());
            }
        }
        dp.get(0).get(0).put(1, 1);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i == 0 && j == 0) || field[i][j] == '#') {
                    continue;
                }
                if (i > 0) {
                    for (Map.Entry<Integer, Integer> entry : dp.get(i - 1).get(j).entrySet()) {
                        int key = entry.getKey();
                        int value = entry.getValue();
                        if (field[i][j] == 'o') {
                            dp.get(i).get(j).put(key + 1, dp.get(i).get(j).getOrDefault(key + 1, 0) + value);
                        } else if (key > 0) {
                            dp.get(i).get(j).put(key - 1, dp.get(i).get(j).getOrDefault(key - 1, 0) + value);
                        }
                    }
                }
                if (j > 0) {
                    for (Map.Entry<Integer, Integer> entry : dp.get(i).get(j - 1).entrySet()) {
                        int key = entry.getKey();
                        int value = entry.getValue();
                        if (field[i][j] == 'o') {
                            dp.get(i).get(j).put(key + 1, dp.get(i).get(j).getOrDefault(key + 1, 0) + value);
                        } else if (key > 0) {
                            dp.get(i).get(j).put(key - 1, dp.get(i).get(j).getOrDefault(key - 1, 0) + value);
                        }
                    }
                }
            }
        }
        long ans = 0;
        for (int x : dp.get(h - 1).get(w - 1).values()) {
            ans += x;
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0