結果

問題 No.1074 増殖
ユーザー tentententen
提出日時 2023-06-07 20:13:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,359 bytes
コンパイル時間 2,880 ms
コンパイル使用メモリ 99,968 KB
実行使用メモリ 49,768 KB
最終ジャッジ日時 2023-08-28 18:03:52
合計ジャッジ時間 7,677 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,508 KB
testcase_01 AC 39 ms
49,768 KB
testcase_02 AC 39 ms
49,448 KB
testcase_03 AC 39 ms
49,500 KB
testcase_04 AC 41 ms
49,464 KB
testcase_05 AC 42 ms
49,664 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] xlow = new int[n];
        int[] ylow = new int[n];
        int[] xhigh = new int[n];
        int[] yhigh = new int[n];
        TreeMap<Integer, Integer> xCompress = new TreeMap<>();
        TreeMap<Integer, Integer> yCompress = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            xlow[i] = sc.nextInt();
            xCompress.put(xlow[i], null);
            ylow[i] = sc.nextInt();
            yCompress.put(ylow[i], null);
            xhigh[i] = sc.nextInt();
            xCompress.put(xhigh[i], null);
            yhigh[i] = sc.nextInt();
            yCompress.put(yhigh[i], null);
        }
        int xsize = xCompress.size();
        int[] xValue = new int[xsize + 1];
        int idx = 0;
        int prev = -1;
        for (int x : xCompress.keySet()) {
            xCompress.put(x, idx);
            if (idx > 0) {
                xValue[idx - 1] = x - prev;
            }
            prev = x;
            idx++;
        }
        int ysize = yCompress.size();
        int[] yValue = new int[ysize + 1];
        idx = 0;
        prev = -1;
        for (int x : yCompress.keySet()) {
            yCompress.put(x, idx);
            if (idx > 0) {
                yValue[idx - 1] = x - prev;
            }
            prev = x;
            idx++;
        }
        boolean[][] field = new boolean[xsize + 1][ysize + 1];
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int ans = 0;
            for (int x = xCompress.get(xlow[i]); x < xCompress.get(xhigh[i]); x++) {
                for (int y = yCompress.get(ylow[i]); y < yCompress.get(yhigh[i]); y++) {
                    if (!field[x][y]) {
                        ans += xValue[x] * yValue[y];
                        field[x][y] = true;
                    }
                }
            }
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0