結果

問題 No.60 魔法少女
ユーザー tentententen
提出日時 2020-11-30 14:18:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,215 ms / 5,000 ms
コード長 1,113 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 74,096 KB
実行使用メモリ 69,364 KB
最終ジャッジ日時 2023-10-11 02:50:33
合計ジャッジ時間 14,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
60,972 KB
testcase_01 AC 145 ms
60,440 KB
testcase_02 AC 145 ms
59,048 KB
testcase_03 AC 155 ms
60,680 KB
testcase_04 AC 960 ms
69,192 KB
testcase_05 AC 955 ms
68,452 KB
testcase_06 AC 1,148 ms
68,596 KB
testcase_07 AC 1,037 ms
68,936 KB
testcase_08 AC 859 ms
69,364 KB
testcase_09 AC 623 ms
68,172 KB
testcase_10 AC 1,152 ms
68,852 KB
testcase_11 AC 477 ms
63,172 KB
testcase_12 AC 863 ms
69,200 KB
testcase_13 AC 1,215 ms
69,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] xArr = new int[n];
		int[] yArr = new int[n];
		int[] hArr = new int[n];
		for (int i = 0; i < n; i++) {
		    xArr[i] = sc.nextInt() + 501;
		    yArr[i] = sc.nextInt() + 501;
		    hArr[i] = sc.nextInt();
		}
		int[][] imos = new int[1010][1010];
		for (int i = 0; i < k; i++) {
		    int x = sc.nextInt() + 501;
		    int y = sc.nextInt() + 501;
		    int w = sc.nextInt();
		    int h = sc.nextInt();
		    int d = sc.nextInt();
		    imos[x][y] += d;
		    imos[Math.min(x + w + 1, 1009)][y] -= d;
		    imos[x][Math.min(y + h + 1, 1009)] -= d;
		    imos[Math.min(x + w + 1, 1009)][Math.min(y + h + 1, 1009)] += d;
		}
		for (int i = 1; i < 1010; i++) {
		    for (int j = 1; j < 1010; j++) {
		        imos[i][j] += imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1];
		    }
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
		    ans += Math.max(0, hArr[i] - imos[xArr[i]][yArr[i]]);
		}
		System.out.println(ans);
	}
}

0