結果

問題 No.755 Zero-Sum Rectangle
ユーザー htensaihtensai
提出日時 2020-01-29 08:50:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 862 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 73,876 KB
実行使用メモリ 60,552 KB
最終ジャッジ日時 2023-10-14 00:14:31
合計ジャッジ時間 13,361 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,788 KB
testcase_01 AC 619 ms
58,976 KB
testcase_02 AC 636 ms
59,996 KB
testcase_03 AC 737 ms
60,272 KB
testcase_04 AC 817 ms
60,388 KB
testcase_05 AC 862 ms
60,136 KB
testcase_06 AC 649 ms
60,504 KB
testcase_07 AC 623 ms
60,252 KB
testcase_08 AC 746 ms
60,124 KB
testcase_09 AC 615 ms
60,552 KB
testcase_10 AC 654 ms
60,280 KB
testcase_11 AC 137 ms
55,732 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[] xArr = new int[n];
        int[] yArr = new int[n];
        for (int i = 0; i < n; i++) {
            xArr[i] = sc.nextInt();
            yArr[i] = sc.nextInt();
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int ans = 0;
            for (int x1 = 1; x1 <= xArr[i]; x1++) {
                for (int x2 = xArr[i]; x2 <= m; x2++) {
                    for (int y1 = 1; y1 <= yArr[i]; y1++) {
                        for (int y2 = yArr[i]; y2 <= m; y2++) {
                            if (sums[x2][y2] - sums[x1 - 1][y2] - sums[x2][y1 - 1] + sums[x1 - 1][y1 - 1] == 0) {
                                ans++;
                            }
                        }
                    }
                }
            }
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
}
0