結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー | tenten |
提出日時 | 2022-10-20 11:59:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 551 ms / 2,000 ms |
コード長 | 2,223 bytes |
コンパイル時間 | 2,218 ms |
コンパイル使用メモリ | 74,556 KB |
実行使用メモリ | 55,320 KB |
最終ジャッジ日時 | 2023-09-12 17:59:40 |
合計ジャッジ時間 | 8,752 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,576 KB |
testcase_01 | AC | 540 ms
54,772 KB |
testcase_02 | AC | 551 ms
54,320 KB |
testcase_03 | AC | 519 ms
54,492 KB |
testcase_04 | AC | 536 ms
55,320 KB |
testcase_05 | AC | 503 ms
54,416 KB |
testcase_06 | AC | 504 ms
55,100 KB |
testcase_07 | AC | 509 ms
54,612 KB |
testcase_08 | AC | 514 ms
54,860 KB |
testcase_09 | AC | 443 ms
54,416 KB |
testcase_10 | AC | 401 ms
54,816 KB |
testcase_11 | AC | 47 ms
49,196 KB |
evil_1 | AC | 554 ms
54,624 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int m = sc.nextInt(); int n = sc.nextInt(); long[][] field = new long[n + 1][n + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { field[i][j] = field[i][j - 1] + field[i - 1][j] - field[i - 1][j - 1] + sc.nextInt(); } } int[][] imos = new int[n + 2][n + 2]; for (int a = 0; a < n; a++) { for (int b = 0; b < n; b++) { for (int c = a + 1; c <= n; c++) { for (int d = b + 1; d <= n; d++) { if (field[c][d] - field[a][d] - field[c][b] + field[a][b] == 0) { imos[a + 1][b + 1]++; imos[a + 1][d + 1]--; imos[c + 1][b + 1]--; imos[c + 1][d + 1]++; } } } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { imos[i][j] += imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1]; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < m; i++) { sb.append(imos[sc.nextInt()][sc.nextInt()]).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }