Submission #71335116
Source Code Expand
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
class Main {
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
FastScanner sc = new FastScanner();
int N = sc.nextInt();
int[] X = new int[N];
int[] R = new int[N];
for (int i = 0; i < N; i++) {
X[i] = sc.nextInt();
R[i] = sc.nextInt();
}
HashMap<Integer,HashSet<Integer>> map = new HashMap<>();
for (int i = 0; i < N; i++) {
map.putIfAbsent(X[i]+R[i],new HashSet<>());
map.get(X[i]+R[i]).add(i);
map.putIfAbsent(X[i]-R[i],new HashSet<>());
map.get(X[i]-R[i]).add(i);
}
HashSet<Integer> decided = new HashSet<>();
boolean[] used = new boolean[N];
for (int i = 0; i < N; i++) {
if (map.get(X[i] - R[i]).size() > 1 && map.get(X[i] + R[i]).size() > 1 && !decided.contains(X[i] - R[i])) {
decided.add(X[i]-R[i]);
used[i] = true;
}
}
for (int i = 0; i < N; i++) {
if (used[i]) continue;
if (map.get(X[i] - R[i]).size() > 1 && !decided.contains(X[i] - R[i])) {
decided.add(X[i]-R[i]);
used[i] = true;
}
}
for (int i = 0; i < N; i++) {
if (used[i]) continue;
if (map.get(X[i] + R[i]).size() > 1 && !decided.contains(X[i] + R[i])) {
decided.add(X[i]+R[i]);
used[i] = true;
}
}
for (int i = 0; i < N; i++) {
if (!used[i]){
decided.add(X[i]+R[i]);
}
}
System.out.println(decided.size());
out.flush();
}
private static class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return buflen > 0;
}
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++];
else return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
return !hasNextByte();
}
public String next() {
if (hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Distribute Bunnies |
| User | AAH_tomato |
| Language | Java24 (OpenJDK 24.0.2) |
| Score | 0 |
| Code Size | 4488 Byte |
| Status | WA |
| Exec Time | 598 ms |
| Memory | 175732 KiB |
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_small_cc_00.txt, 02_small_cc_01.txt, 02_small_cc_02.txt, 02_small_cc_03.txt, 02_small_cc_04.txt, 02_small_cc_05.txt, 02_small_cc_06.txt, 02_small_cc_07.txt, 02_small_cc_08.txt, 02_small_cc_09.txt, 02_small_cc_10.txt, 02_small_cc_11.txt, 02_small_cc_12.txt, 02_small_cc_13.txt, 02_small_cc_14.txt, 02_small_cc_15.txt, 02_small_cc_16.txt, 02_small_cc_17.txt, 02_small_cc_18.txt, 02_small_cc_19.txt, 03_path_00.txt, 03_path_01.txt, 04_cycle_00.txt, 04_cycle_01.txt, 05_namori_00.txt, 05_namori_01.txt, 05_namori_02.txt, 05_namori_03.txt, 05_namori_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 41 ms | 38024 KiB |
| 00_sample_01.txt | AC | 39 ms | 38024 KiB |
| 00_sample_02.txt | WA | 37 ms | 37668 KiB |
| 01_random_00.txt | WA | 440 ms | 136732 KiB |
| 01_random_01.txt | WA | 537 ms | 132932 KiB |
| 01_random_02.txt | WA | 501 ms | 145780 KiB |
| 01_random_03.txt | WA | 582 ms | 175732 KiB |
| 01_random_04.txt | WA | 455 ms | 134640 KiB |
| 01_random_05.txt | WA | 567 ms | 158576 KiB |
| 01_random_06.txt | WA | 369 ms | 118320 KiB |
| 01_random_07.txt | WA | 580 ms | 156828 KiB |
| 01_random_08.txt | WA | 374 ms | 119376 KiB |
| 01_random_09.txt | WA | 496 ms | 120140 KiB |
| 02_small_cc_00.txt | AC | 551 ms | 174312 KiB |
| 02_small_cc_01.txt | WA | 594 ms | 159668 KiB |
| 02_small_cc_02.txt | WA | 574 ms | 157772 KiB |
| 02_small_cc_03.txt | WA | 586 ms | 158100 KiB |
| 02_small_cc_04.txt | WA | 556 ms | 153528 KiB |
| 02_small_cc_05.txt | WA | 572 ms | 152712 KiB |
| 02_small_cc_06.txt | WA | 540 ms | 151496 KiB |
| 02_small_cc_07.txt | WA | 539 ms | 150416 KiB |
| 02_small_cc_08.txt | WA | 531 ms | 147440 KiB |
| 02_small_cc_09.txt | WA | 529 ms | 146624 KiB |
| 02_small_cc_10.txt | WA | 487 ms | 145976 KiB |
| 02_small_cc_11.txt | WA | 541 ms | 146156 KiB |
| 02_small_cc_12.txt | WA | 515 ms | 145292 KiB |
| 02_small_cc_13.txt | WA | 559 ms | 145584 KiB |
| 02_small_cc_14.txt | WA | 518 ms | 139740 KiB |
| 02_small_cc_15.txt | WA | 462 ms | 135644 KiB |
| 02_small_cc_16.txt | WA | 476 ms | 135480 KiB |
| 02_small_cc_17.txt | WA | 521 ms | 137012 KiB |
| 02_small_cc_18.txt | WA | 468 ms | 133444 KiB |
| 02_small_cc_19.txt | WA | 483 ms | 133104 KiB |
| 03_path_00.txt | WA | 452 ms | 130936 KiB |
| 03_path_01.txt | WA | 527 ms | 129812 KiB |
| 04_cycle_00.txt | AC | 444 ms | 129712 KiB |
| 04_cycle_01.txt | WA | 508 ms | 128928 KiB |
| 05_namori_00.txt | WA | 598 ms | 126732 KiB |
| 05_namori_01.txt | WA | 598 ms | 126888 KiB |
| 05_namori_02.txt | WA | 574 ms | 126632 KiB |
| 05_namori_03.txt | WA | 568 ms | 127688 KiB |
| 05_namori_04.txt | WA | 594 ms | 126852 KiB |