結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
![]() |
提出日時 | 2020-01-06 15:21:32 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,349 bytes |
コンパイル時間 | 2,579 ms |
コンパイル使用メモリ | 79,200 KB |
実行使用メモリ | 61,056 KB |
最終ジャッジ日時 | 2024-11-23 00:01:52 |
合計ジャッジ時間 | 10,307 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 WA * 8 TLE * 1 |
ソースコード
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[] ans = new int[n]; 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(); } for (int a = 1; a <= m; a++) { HashSet<Integer> targets = new HashSet<>(); for (int i = 0; i < n; i++) { if (xArr[i] >= a) { targets.add(i); } } if (targets.size() == 0) { continue; } for (int b = m; b >= a; b--) { for (int i = 0; i < n; i++) { if (xArr[i] > b) { targets.remove(i); } } if (targets.size() == 0) { continue; } for (int c = 1; c <= m; c++) { for (int i = 0; i < n; i++) { if (yArr[i] < c) { targets.remove(i); } } if (targets.size() == 0) { continue; } for (int d = c; d <= m; d++) { long sum = sums[b][d] - sums[a - 1][d] - sums[b][c - 1] + sums[a - 1][c - 1]; if (sum == 0) { for (int i = 0; i < n; i++) { if (xArr[i] >= a && xArr[i] <= b && yArr[i] >= c && yArr[i] <= d) { ans[i]++; } } } } } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } }