結果

問題 No.755 Zero-Sum Rectangle
ユーザー htensaihtensai
提出日時 2020-01-06 15:21:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,349 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 61,292 KB
最終ジャッジ日時 2024-05-02 10:51:15
合計ジャッジ時間 10,269 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
53,980 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 380 ms
59,252 KB
testcase_10 AC 381 ms
59,224 KB
testcase_11 AC 145 ms
53,848 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[][] sums = new long[m + 1][m + 1];
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= m; j++) {
                sums[i][j] = sc.nextInt() + sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1];
            }
        }
        int[] ans = new int[n];
        int[] xArr = new int[n];
        int[] yArr = new int[n];
        for (int i = 0; i < n; i++) {
            xArr[i] = sc.nextInt();
            yArr[i] = sc.nextInt();
        }
        for (int a = 1; a <= m; a++) {
            HashSet<Integer> targets = new HashSet<>();
            for (int i = 0; i < n; i++) {
                if (xArr[i] >= a) {
                    targets.add(i);
                }
            }
            if (targets.size() == 0) {
                continue;
            }
            for (int b = m; b >= a; b--) {
                for (int i = 0; i < n; i++) {
                    if (xArr[i] > b) {
                        targets.remove(i);
                    }
                }
                if (targets.size() == 0) {
                    continue;
                }
                for (int c = 1; c <= m; c++) {
                    for (int i = 0; i < n; i++) {
                        if (yArr[i] < c) {
                            targets.remove(i);
                        }
                    }
                    if (targets.size() == 0) {
                        continue;
                    }
                    for (int d = c; d <= m; d++) {
                        long sum = sums[b][d] - sums[a - 1][d] - sums[b][c - 1] + sums[a - 1][c - 1];
                        if (sum == 0) {
                            for (int i = 0; i < n; i++) {
                                if (xArr[i] >= a && xArr[i] <= b && yArr[i] >= c && yArr[i] <= d) {
                                    ans[i]++;
                                }
                            }
                        }
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(ans[i]).append("\n");
        }
        System.out.print(sb);
    }
}
0