結果

問題 No.60 魔法少女
ユーザー creep04creep04
提出日時 2017-10-26 23:38:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 480 ms / 5,000 ms
コード長 1,733 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 77,152 KB
実行使用メモリ 55,980 KB
最終ジャッジ日時 2024-05-01 15:21:28
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
50,436 KB
testcase_01 AC 125 ms
50,380 KB
testcase_02 AC 135 ms
50,504 KB
testcase_03 AC 119 ms
50,416 KB
testcase_04 AC 402 ms
55,012 KB
testcase_05 AC 400 ms
55,332 KB
testcase_06 AC 480 ms
55,980 KB
testcase_07 AC 410 ms
55,100 KB
testcase_08 AC 359 ms
55,236 KB
testcase_09 AC 295 ms
55,028 KB
testcase_10 AC 453 ms
55,744 KB
testcase_11 AC 248 ms
54,500 KB
testcase_12 AC 348 ms
55,212 KB
testcase_13 AC 468 ms
55,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
public class Main {
	static FastScanner sc;
	public static void main(String[] args) {
		sc = new FastScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ene[][] = new int[1001][1001];	// 敵のHPのマップ
		int dif[][] = new int[1001][1001];	// 与ダメージのマップ
		for (int i=0; i<N; i++) {
			int x = sc.nextInt() + 500;
			int y = sc.nextInt() + 500;
			int hp = sc.nextInt();
			ene[x][y] = hp;	// -500〜500を0〜1000に
		}
		for (int i=0; i<K; i++) {
			int x = sc.nextInt() + 500;
			int y = sc.nextInt() + 500;
			int wx = sc.nextInt();
			int wy = sc.nextInt();
			int d = sc.nextInt();
			dif[x][y] += d;
			if (x+wx+1<1001 && y+wy+1<1001) dif[x+wx+1][y+wy+1] += d;
			if (x+wx+1<1001) dif[x+wx+1][y] -= d;
			if (y+wy+1<1001) dif[x][y+wy+1] -= d;
		}
		
		for (int y=0; y<1001; y++) {
			for (int x=1; x<1001; x++) {
				dif[x][y] += dif[x-1][y];
			}
		}
		for (int x=0; x<1001; x++) {
			for (int y=1; y<1001; y++) {
				dif[x][y] += dif[x][y-1];
			}
		}
		
		int ans = 0;
		for (int y=0; y<1001; y++) {
			for (int x=0; x<1001; x++) {
				if (ene[x][y]-dif[x][y]>0) ans += ene[x][y]-dif[x][y];
			}
		}
		
		System.out.println(ans);
	}
	
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		
		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}
0