結果

問題 No.60 魔法少女
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2015-06-24 18:54:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,248 ms / 5,000 ms
コード長 1,690 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 74,360 KB
実行使用メモリ 69,216 KB
最終ジャッジ日時 2023-09-22 00:34:28
合計ジャッジ時間 13,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
58,204 KB
testcase_01 AC 163 ms
60,220 KB
testcase_02 AC 169 ms
60,196 KB
testcase_03 AC 170 ms
60,136 KB
testcase_04 AC 1,024 ms
68,508 KB
testcase_05 AC 990 ms
68,700 KB
testcase_06 AC 1,233 ms
66,944 KB
testcase_07 AC 1,110 ms
69,068 KB
testcase_08 AC 876 ms
66,416 KB
testcase_09 AC 657 ms
64,928 KB
testcase_10 AC 1,212 ms
68,616 KB
testcase_11 AC 539 ms
62,704 KB
testcase_12 AC 965 ms
66,736 KB
testcase_13 AC 1,248 ms
69,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	static int N, K;
	static int[] X, Y, HP;
	static int[] AX, AY, W, H, D;
	
	public static int solve(){
		int[][] damage = new int[1001][1001];
		for (int y = 0; y < 1001; y++) {
			for (int x = 0; x < 1001; x++) {
				damage[y][x] = 0;
			}
		}
		
		for (int i = 0; i < K; i++) {
			int x = AX[i], y = AY[i];
			damage[y][x] += D[i];
			
			if(x + W[i] + 1 <= 1000)
			{
				damage[y][x+W[i]+1] += -1 * D[i];
				if(y+H[i]+1 <= 1000)
				{
					damage[y+H[i]+1][x+W[i]+1] += D[i];
				}
			}
			if(y+H[i]+1 <= 1000)
			{
				damage[y+H[i]+1][x] += -1 * D[i];
			}
		}
		
		for (int y = 0; y <= 1000; y++) {
			for (int x = 1; x <= 1000; x++) {
				damage[y][x] += damage[y][x-1];
			}
		}
		
		for (int x = 0; x <= 1000; x++) {
			for (int y = 1; y <= 1000; y++) {
				damage[y][x] += damage[y-1][x];
			}
		}
		
		int ret = 0;
		for (int i = 0; i < N; i++) {
			int delta = HP[i] - damage[Y[i]][X[i]];
			if(delta > 0) ret += delta;
		}
		
		System.out.println(ret);
		
		return 0;
	}
	
	public static void main(String[] args){
		Scanner S = new Scanner(System.in);
		
		N = S.nextInt();
		K = S.nextInt();
		
		X = new int[N];
		Y = new int[N];
		HP = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = S.nextInt() + 500;
			Y[i] = S.nextInt() + 500;
			HP[i] = S.nextInt();
		}
		
		AX = new int[K];
		AY = new int[K];
		W = new int[K];
		H = new int[K];
		D = new int[K];
		for (int i = 0; i < K; i++) {
			AX[i] = S.nextInt() + 500;
			AY[i] = S.nextInt() + 500;
			W[i] = S.nextInt();
			H[i] = S.nextInt();
			D[i] = S.nextInt();
		}
		
		solve();
	}
}
0