結果

問題 No.755 Zero-Sum Rectangle
ユーザー htensaihtensai
提出日時 2020-01-06 15:24:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,770 ms / 2,000 ms
コード長 2,360 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 79,780 KB
実行使用メモリ 49,528 KB
最終ジャッジ日時 2024-05-02 10:51:37
合計ジャッジ時間 14,519 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
45,140 KB
testcase_01 AC 1,770 ms
48,276 KB
testcase_02 AC 771 ms
48,372 KB
testcase_03 AC 770 ms
48,316 KB
testcase_04 AC 729 ms
48,368 KB
testcase_05 AC 616 ms
48,728 KB
testcase_06 AC 670 ms
48,808 KB
testcase_07 AC 777 ms
49,528 KB
testcase_08 AC 716 ms
48,892 KB
testcase_09 AC 761 ms
48,616 KB
testcase_10 AC 674 ms
48,988 KB
testcase_11 AC 129 ms
41,520 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++) {
                    int count = 0;
                    for (int x : targets) {
                        if (yArr[x] >= c) {
                            count++;
                        }
                    }
                    if (count == 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