結果

問題 No.60 魔法少女
ユーザー GrenacheGrenache
提出日時 2016-05-18 07:59:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 617 ms / 5,000 ms
コード長 2,457 bytes
コンパイル時間 3,726 ms
コンパイル使用メモリ 79,280 KB
実行使用メモリ 55,260 KB
最終ジャッジ日時 2024-04-15 22:52:49
合計ジャッジ時間 10,219 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
45,980 KB
testcase_01 AC 89 ms
45,612 KB
testcase_02 AC 91 ms
45,648 KB
testcase_03 AC 92 ms
45,792 KB
testcase_04 AC 464 ms
54,016 KB
testcase_05 AC 457 ms
54,972 KB
testcase_06 AC 597 ms
54,780 KB
testcase_07 AC 531 ms
54,756 KB
testcase_08 AC 370 ms
54,480 KB
testcase_09 AC 263 ms
50,520 KB
testcase_10 AC 617 ms
55,260 KB
testcase_11 AC 209 ms
45,684 KB
testcase_12 AC 364 ms
51,536 KB
testcase_13 AC 596 ms
54,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder60 {

    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		final int MAX = 1001;

		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] x = new int[n];
		int[] y = new int[n];
		int[] hp = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt() + 500;
			y[i] = sc.nextInt() + 500;
			hp[i] = sc.nextInt();
		}

		int[][] mat = new int[MAX + 1][MAX + 1];

		for (int i = 0; i < k; i++) {
			int ax = sc.nextInt() + 500;
			int ay = sc.nextInt() + 500;
			int w = sc.nextInt();
			int h = sc.nextInt();
			int d = sc.nextInt();

			mat[ay][ax] += d;
			mat[ay][Math.min(MAX, ax + w + 1)] -= d;
			mat[Math.min(MAX, ay + h + 1)][ax] -= d;
			mat[Math.min(MAX, ay + h + 1)][Math.min(MAX, ax + w + 1)] += d;
		}

		for (int i = 0; i <= MAX; i++) {
			for (int j = 1; j <= MAX; j++) {
				mat[i][j] += mat[i][j - 1];
			}
		}
		for (int i = 1; i <= MAX; i++) {
			for (int j = 0; j <= MAX; j++) {
				mat[i][j] += mat[i - 1][j];
			}
		}

		int ret = 0;
		for (int i = 0; i < n; i++) {
			int tmp = hp[i] - mat[y[i]][x[i]];
			if (tmp > 0) {
				ret += tmp;
			}
		}

		pr.println(ret);

//		for (int i = 0; i <= MAX; i++) {
//			for (int j = 0; j <= MAX; j++) {
//				pr.print(mat[i][j]);
//				pr.print(" ");
//			}
//			pr.println();
//		}

		pr.close();
		sc.close();
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0