結果

問題 No.755 Zero-Sum Rectangle
ユーザー tentententen
提出日時 2020-09-01 16:55:53
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,792 bytes
コンパイル時間 2,790 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 41,892 KB
最終ジャッジ日時 2024-04-29 22:33:47
合計ジャッジ時間 13,633 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
41,892 KB
testcase_01 TLE -
testcase_02 AC 622 ms
40,448 KB
testcase_03 AC 616 ms
40,244 KB
testcase_04 AC 424 ms
40,368 KB
testcase_05 AC 373 ms
40,288 KB
testcase_06 AC 418 ms
40,600 KB
testcase_07 AC 564 ms
40,740 KB
testcase_08 AC 518 ms
40,644 KB
testcase_09 AC 435 ms
40,360 KB
testcase_10 AC 397 ms
40,664 KB
testcase_11 AC 54 ms
36,756 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] first = br.readLine().split(" ", 2);
    	int n = Integer.parseInt(first[0]);
    	int m = Integer.parseInt(first[1]);
        long[][] field = new long[m + 1][m + 1];
        for (int i = 1; i <= m; i++) {
            String[] line = br.readLine().split(" ", m);
            for (int j = 1; j <= m; j++) {
                field[i][j] = field[i][j - 1] + field[i - 1][j] - field[i - 1][j - 1] + Integer.parseInt(line[j - 1]);
            }
        }
        int[] xArr = new int[n];
        int[] yArr = new int[n];
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ", 2);
            xArr[i] = Integer.parseInt(line[0]);
            yArr[i] = Integer.parseInt(line[1]);
        }
        int[] counts = new int[n];
        for (int a = 1; a <= m; a++) {
            for (int b = 1; b <= m; b++) {
                for (int c = a; c <= m; c++) {
                    for (int d = b; d <= m; d++) {
                        if (field[c][d] - field[a - 1][d] - field[c][b - 1] + field[a- 1][b - 1] != 0) {
                            continue;
                        }
                        for (int i = 0; i < n; i++) {
                            if (xArr[i] >= a && xArr[i] <= c && yArr[i] >= b && yArr[i] <= d) {
                                counts[i]++;
                            }
                        }
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int x : counts) {
            sb.append(x).append("\n");
        }
    	System.out.print(sb);
    }
}
0