結果

問題 No.60 魔法少女
ユーザー scachescache
提出日時 2014-11-26 18:34:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,185 ms / 5,000 ms
コード長 1,508 bytes
コンパイル時間 3,683 ms
コンパイル使用メモリ 74,484 KB
実行使用メモリ 79,284 KB
最終ジャッジ日時 2023-09-01 22:13:08
合計ジャッジ時間 15,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
65,136 KB
testcase_01 AC 156 ms
64,548 KB
testcase_02 AC 155 ms
65,092 KB
testcase_03 AC 161 ms
64,804 KB
testcase_04 AC 930 ms
76,888 KB
testcase_05 AC 952 ms
76,976 KB
testcase_06 AC 1,150 ms
79,284 KB
testcase_07 AC 1,005 ms
78,904 KB
testcase_08 AC 871 ms
75,088 KB
testcase_09 AC 620 ms
74,668 KB
testcase_10 AC 1,173 ms
79,160 KB
testcase_11 AC 506 ms
67,136 KB
testcase_12 AC 869 ms
76,916 KB
testcase_13 AC 1,185 ms
77,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

/**
 * yukicoder no.60 魔法少女 
 * @author scache
 *
 */
public class Main60 {
	public static void main(String[] args) {
		Main60 p = new Main60();
	}

	public Main60() {
		Scanner sc = new Scanner(System.in);
		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();
		}
		
		solve(n, k, x, y, hp, sc);
	}

	private final int MAX_W =1001;
	private final int MAX_H =1001;
	public void solve(int n, int k, int[] x, int[] y, int[] hp, Scanner sc) {
		int[][] field = new int[MAX_W+501][MAX_H+501];
		for(int i=0;i<k;i++){
			int ax = sc.nextInt()+500;
			int ay = sc.nextInt()+500;
			int w = sc.nextInt()+1;
			int h = sc.nextInt()+1;
			int d = sc.nextInt();
			
			field[ax][ay] += d;
//			if(ax+w < MAX_W && ay+h < MAX_H)
				field[ax+w][ay+h] += d;
//			if(ax+w < MAX_W)
				field[ax+w][ay] -= d;
//			if(ay+h < MAX_H)
				field[ax][ay+h] -= d;
		}
		
		for(int i=0;i<MAX_W-1;i++){
			for(int j=0;j<MAX_H;j++){
				field[i+1][j] += field[i][j];
			}
		}
		
		for(int i=0;i<MAX_W;i++){
			for(int j=0;j<MAX_H-1;j++){
				field[i][j+1] += field[i][j];
			}
		}
		
		int res = 0;
		for(int i=0;i<x.length;i++){
			res += Math.max(0, hp[i]-field[x[i]][y[i]]);
		}
		
		
		System.out.println(res);
		
		
	}

	
}
0