結果
| 問題 |
No.1074 増殖
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-06-07 20:13:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,359 bytes |
| コンパイル時間 | 3,686 ms |
| コンパイル使用メモリ | 93,884 KB |
| 実行使用メモリ | 791,216 KB |
| 最終ジャッジ日時 | 2024-12-30 02:05:03 |
| 合計ジャッジ時間 | 23,330 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 TLE * 3 MLE * 5 |
ソースコード
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();
}
}
tenten