結果

問題 No.1490 スライムと爆弾
ユーザー ks2mks2m
提出日時 2021-04-23 22:37:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 740 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 90,748 KB
最終ジャッジ日時 2023-09-17 12:42:13
合計ジャッジ時間 13,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
48,996 KB
testcase_01 AC 44 ms
49,104 KB
testcase_02 AC 46 ms
49,008 KB
testcase_03 AC 48 ms
49,008 KB
testcase_04 AC 49 ms
49,128 KB
testcase_05 AC 46 ms
49,076 KB
testcase_06 AC 48 ms
49,012 KB
testcase_07 AC 50 ms
49,112 KB
testcase_08 AC 45 ms
49,152 KB
testcase_09 AC 47 ms
49,352 KB
testcase_10 AC 48 ms
49,032 KB
testcase_11 AC 47 ms
47,188 KB
testcase_12 AC 47 ms
49,280 KB
testcase_13 AC 513 ms
67,880 KB
testcase_14 AC 528 ms
73,636 KB
testcase_15 AC 465 ms
69,704 KB
testcase_16 AC 458 ms
66,960 KB
testcase_17 AC 428 ms
75,168 KB
testcase_18 AC 560 ms
81,296 KB
testcase_19 AC 534 ms
72,292 KB
testcase_20 AC 496 ms
67,976 KB
testcase_21 AC 406 ms
69,320 KB
testcase_22 AC 515 ms
68,612 KB
testcase_23 AC 43 ms
49,172 KB
testcase_24 AC 44 ms
49,152 KB
testcase_25 AC 628 ms
86,260 KB
testcase_26 AC 625 ms
86,916 KB
testcase_27 AC 625 ms
86,480 KB
testcase_28 AC 625 ms
88,692 KB
testcase_29 AC 623 ms
86,856 KB
testcase_30 AC 740 ms
90,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		int n = Integer.parseInt(sa[2]);
		int m = Integer.parseInt(sa[3]);
		int[] t = new int[n];
		int[] u = new int[n];
		int[] l = new int[n];
		int[] r = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			t[i] = Integer.parseInt(sa[0]) - 1;
			u[i] = Integer.parseInt(sa[1]);
			l[i] = Integer.parseInt(sa[2]) - 1;
			r[i] = Integer.parseInt(sa[3]);
			a[i] = Integer.parseInt(sa[4]);
		}
		int[] x = new int[m];
		int[] y = new int[m];
		int[] b = new int[m];
		int[] c = new int[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			x[i] = Integer.parseInt(sa[0]);
			y[i] = Integer.parseInt(sa[1]);
			b[i] = Integer.parseInt(sa[2]);
			c[i] = Integer.parseInt(sa[3]);
		}
		br.close();

		long[][] z = new long[h + 2][w + 2];
		for (int i = 0; i < m; i++) {
			int lx = Math.max(x[i] - b[i], 0);
			int rx = Math.min(x[i] + b[i] + 1, h + 1);
			int ly = Math.max(y[i] - b[i], 0);
			int ry = Math.min(y[i] + b[i] + 1, w + 1);
			z[lx][ly] += c[i];
			z[lx][ry] -= c[i];
			z[rx][ly] -= c[i];
			z[rx][ry] += c[i];
		}
		for (int i = 0; i <= h + 1; i++) {
			for (int j = 0; j <= w; j++) {
				z[i][j + 1] += z[i][j];
			}
		}
		for (int j = 0; j <= w + 1; j++) {
			for (int i = 0; i <= h; i++) {
				z[i + 1][j] += z[i][j];
			}
		}
		for (int i = 0; i <= h + 1; i++) {
			for (int j = 0; j <= w; j++) {
				z[i][j + 1] += z[i][j];
			}
		}
		for (int j = 0; j <= w + 1; j++) {
			for (int i = 0; i <= h; i++) {
				z[i + 1][j] += z[i][j];
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			long dam = 0;
			dam += z[u[i]][r[i]];
			dam -= z[u[i]][l[i]];
			dam -= z[t[i]][r[i]];
			dam += z[t[i]][l[i]];
			if (dam < a[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}
0