結果

問題 No.755 Zero-Sum Rectangle
ユーザー tentententen
提出日時 2021-11-02 17:26:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,803 ms / 2,000 ms
コード長 2,142 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 43,424 KB
最終ジャッジ日時 2024-04-20 03:16:09
合計ジャッジ時間 12,382 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
42,388 KB
testcase_01 AC 1,803 ms
42,448 KB
testcase_02 AC 554 ms
43,356 KB
testcase_03 AC 533 ms
42,600 KB
testcase_04 AC 472 ms
42,648 KB
testcase_05 AC 497 ms
42,648 KB
testcase_06 AC 455 ms
42,892 KB
testcase_07 AC 511 ms
43,076 KB
testcase_08 AC 526 ms
43,092 KB
testcase_09 AC 449 ms
43,268 KB
testcase_10 AC 406 ms
43,424 KB
testcase_11 AC 55 ms
36,892 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[][] field = new long[m + 1][m + 1];
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= m; j++) {
                field[i][j] = field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1] + sc.nextInt();
            }
        }
        int[] xs = new int[n];
        int[] ys = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
            ys[i] = sc.nextInt();
        }
        int[] ans = new int[n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = i + 1; k <= m; k++) {
                    for (int l = j + 1; l <= m; l++) {
                        if (field[k][l] - field[i][l] - field[k][j] + field[i][j] == 0) {
                            for (int a = 0; a < n; a++) {
                                if (xs[a] > i && xs[a] <= k && ys[a] > j && ys[a] <= l)  {
                                    ans[a]++;
                                }
                            }
                        }
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int x : ans) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0