結果

問題 No.1490 スライムと爆弾
ユーザー tenten
提出日時 2021-04-30 08:57:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 2,604 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 77,680 KB
実行使用メモリ 104,460 KB
最終ジャッジ日時 2024-07-18 07:51:14
合計ジャッジ時間 11,264 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] tops = new int[n];
        int[] unders = new int[n];
        int[] lefts = new int[n];
        int[] rights = new int[n];
        int[] lives = new int[n];
        for (int i = 0; i < n; i++) {
            tops[i] = sc.nextInt();
            unders[i] = sc.nextInt();
            lefts[i] = sc.nextInt();
            rights[i] = sc.nextInt();
            lives[i] = sc.nextInt();
        }
        long[][] field = new long[h + 2][w + 2];
        for (int i = 0; i < m; i++) {
            int row = sc.nextInt();
            int col = sc.nextInt();
            int b = sc.nextInt();
            int power = sc.nextInt();
            int startR = Math.max(1, row - b);
            int startC = Math.max(1, col - b);
            int endR = Math.min(h, row + b);
            int endC = Math.min(w, col + b);
            field[startR][startC] += power;
            field[endR + 1][startC] -= power;
            field[startR][endC + 1] -= power;
            field[endR + 1][endC + 1] += power;
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                field[i][j] += field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1];
            }
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                field[i][j] += field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1];
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            long total = field[unders[i]][rights[i]] - field[tops[i] - 1][rights[i]] - field[unders[i]][lefts[i] - 1] + field[tops[i] - 1][lefts[i] - 1];
            if (total < lives[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}

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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0