結果
| 問題 |
No.60 魔法少女
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-10 10:40:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 5,000 ms |
| コード長 | 2,102 bytes |
| コンパイル時間 | 2,661 ms |
| コンパイル使用メモリ | 77,596 KB |
| 実行使用メモリ | 54,324 KB |
| 最終ジャッジ日時 | 2024-11-20 19:56:18 |
| 合計ジャッジ時間 | 7,293 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = sc.nextInt();
int[] xs = new int[n];
int[] ys = new int[n];
int[] hs = new int[n];
for (int i = 0; i < n; i++) {
xs[i] = sc.nextInt() + 501;
ys[i] = sc.nextInt() + 501;
hs[i] = sc.nextInt();
}
int[][] imos = new int[1003][1003];
for (int i = 0; i < k; i++) {
int x = sc.nextInt() + 501;
int y = sc.nextInt() + 501;
int w = sc.nextInt();
int h = sc.nextInt();
int d = sc.nextInt();
imos[x][y] += d;
imos[Math.min(x + w + 1, 1002)][y] -= d;
imos[x][Math.min(y + h + 1, 1002)] -= d;
imos[Math.min(x + w + 1, 1002)][Math.min(y + h + 1, 1002)] += d;
}
for (int i = 1; i < 1003; i++) {
for (int j = 1; j < 1003; j++) {
imos[i][j] += imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1];
}
}
long ans = 0;
for (int i = 0; i < n; i++) {
ans += Math.max(0, hs[i] - imos[xs[i]][ys[i]]);
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten