結果

問題 No.60 魔法少女
ユーザー scachescache
提出日時 2014-11-17 07:42:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,185 ms / 5,000 ms
コード長 1,496 bytes
コンパイル時間 3,327 ms
コンパイル使用メモリ 76,672 KB
実行使用メモリ 55,040 KB
最終ジャッジ日時 2023-08-30 20:22:36
合計ジャッジ時間 15,166 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
46,096 KB
testcase_01 AC 157 ms
46,580 KB
testcase_02 AC 157 ms
46,328 KB
testcase_03 AC 162 ms
46,064 KB
testcase_04 AC 941 ms
54,084 KB
testcase_05 AC 944 ms
54,996 KB
testcase_06 AC 1,147 ms
54,924 KB
testcase_07 AC 1,020 ms
54,668 KB
testcase_08 AC 851 ms
54,596 KB
testcase_09 AC 608 ms
53,796 KB
testcase_10 AC 1,142 ms
55,040 KB
testcase_11 AC 495 ms
48,828 KB
testcase_12 AC 860 ms
54,976 KB
testcase_13 AC 1,185 ms
54,620 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][MAX_H];
		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