結果

問題 No.755 Zero-Sum Rectangle
ユーザー tentententen
提出日時 2020-09-01 17:08:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 646 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 42,248 KB
最終ジャッジ日時 2024-04-29 23:23:57
合計ジャッジ時間 10,861 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
42,248 KB
testcase_01 AC 347 ms
40,268 KB
testcase_02 AC 438 ms
40,140 KB
testcase_03 AC 571 ms
40,272 KB
testcase_04 AC 606 ms
39,856 KB
testcase_05 AC 646 ms
40,292 KB
testcase_06 AC 423 ms
40,120 KB
testcase_07 AC 415 ms
40,516 KB
testcase_08 AC 560 ms
40,404 KB
testcase_09 AC 396 ms
40,780 KB
testcase_10 AC 461 ms
41,028 KB
testcase_11 AC 50 ms
36,992 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]);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int count = 0;
            String[] line = br.readLine().split(" ", 2);
            int x = Integer.parseInt(line[0]);
            int y = Integer.parseInt(line[1]);
            for (int a = 1; a <= x; a++) {
                for (int b = 1; b <= y; b++) {
                    for (int c = x; c <= m; c++) {
                        for (int d = y; d <= m; d++) {
                            if (field[c][d] - field[a - 1][d] - field[c][b - 1] + field[a- 1][b - 1] == 0) {
                                count++;
                            }
                        }
                    }
                }
            }
            sb.append(count).append("\n");
        }
    	System.out.print(sb);
    }
}
0