結果
問題 |
No.60 魔法少女
|
ユーザー |
|
提出日時 | 2016-05-18 07:59:27 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 614 ms / 5,000 ms |
コード長 | 2,457 bytes |
コンパイル時間 | 4,412 ms |
コンパイル使用メモリ | 78,988 KB |
実行使用メモリ | 54,324 KB |
最終ジャッジ日時 | 2024-10-06 05:26:19 |
合計ジャッジ時間 | 10,034 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 |
ソースコード
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); } } }