結果

問題 No.60 魔法少女
ユーザー tentententen
提出日時 2021-11-10 10:40:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 474 ms / 5,000 ms
コード長 2,102 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 63,680 KB
最終ジャッジ日時 2024-04-30 21:45:47
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
56,488 KB
testcase_01 AC 95 ms
56,504 KB
testcase_02 AC 93 ms
56,408 KB
testcase_03 AC 99 ms
56,588 KB
testcase_04 AC 373 ms
63,512 KB
testcase_05 AC 373 ms
62,864 KB
testcase_06 AC 462 ms
62,692 KB
testcase_07 AC 416 ms
63,680 KB
testcase_08 AC 333 ms
60,724 KB
testcase_09 AC 254 ms
60,084 KB
testcase_10 AC 443 ms
62,656 KB
testcase_11 AC 199 ms
55,592 KB
testcase_12 AC 318 ms
60,580 KB
testcase_13 AC 474 ms
62,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0