結果

問題 No.506 限られたジャパリまん
ユーザー tentententen
提出日時 2020-12-25 09:23:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,970 bytes
コンパイル時間 2,683 ms
コンパイル使用メモリ 76,460 KB
実行使用メモリ 60,000 KB
最終ジャッジ日時 2023-09-10 12:57:03
合計ジャッジ時間 7,326 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,272 KB
testcase_01 AC 119 ms
55,816 KB
testcase_02 AC 123 ms
55,532 KB
testcase_03 AC 122 ms
55,824 KB
testcase_04 AC 142 ms
57,716 KB
testcase_05 AC 132 ms
55,780 KB
testcase_06 AC 121 ms
55,812 KB
testcase_07 AC 133 ms
55,820 KB
testcase_08 AC 240 ms
59,832 KB
testcase_09 AC 191 ms
59,724 KB
testcase_10 AC 138 ms
56,036 KB
testcase_11 AC 233 ms
59,736 KB
testcase_12 AC 227 ms
60,000 KB
testcase_13 AC 124 ms
55,748 KB
testcase_14 AC 133 ms
55,776 KB
testcase_15 AC 124 ms
55,544 KB
testcase_16 AC 227 ms
59,784 KB
testcase_17 AC 142 ms
55,972 KB
testcase_18 AC 150 ms
55,532 KB
testcase_19 AC 172 ms
59,228 KB
testcase_20 AC 171 ms
59,096 KB
testcase_21 AC 166 ms
58,576 KB
testcase_22 AC 182 ms
59,500 KB
testcase_23 AC 173 ms
58,696 KB
testcase_24 AC 156 ms
55,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        int p = sc.nextInt();
        HashMap<Integer, Integer> places = new HashMap<>();
        String[] names = new String[k];
        for (int i = 0; i < k; i++) {
            places.put(sc.nextInt() * 100 + sc.nextInt(), i);
            names[i] = sc.next();
        }
        long max = 0;
        int key = 0;
        long[][] counts = new long[h + 1][w + 1];
        for (int i = 0; i < (1 << k); i++) {
            if (getPop(i) != p) {
                continue;
            }
            counts[0][0] = 1;
            for (int a = 0; a <= h; a++) {
                for (int b = 0; b <= w; b++) {
                    if (a == 0 && b == 0) {
                        continue;
                    }
                    counts[a][b] = 0;
                    if (places.containsKey(a * 100 + b) && ((1 << places.get(a * 100 + b)) & i) == 0) {
                        continue;
                    }
                    if (a > 0) {
                        counts[a][b] += counts[a - 1][b];
                    }
                    if (b > 0) {
                        counts[a][b] += counts[a][b - 1];
                    }
                }
            }
            if (max < counts[h][w]) {
                max = counts[h][w];
                key = i;
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append(max % 1000000007).append("\n");
        for (int i = 0; i < k; i++) {
            if (key % 2 == 1) {
                sb.append(names[i]).append("\n");
            }
            key /= 2;
        }
        System.out.print(sb);
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x /= 2;
        }
        return pop;
    }
}
0