Non vado in TLE o hitto il memory limit, ma con la mia soluzione non passo tutti i test.
Ho notato che per i test che non passo (per output incorretto) il tempo è stranamente basso.
Codice:
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
Map<Integer, ArrayList<Integer>> xMap = new HashMap<>();
Map<Integer, ArrayList<Integer>> yMap = new HashMap<>();
int N = in.readInt();
for (int i = 0; i < N; i++) {
int x = in.readInt();
xMap.putIfAbsent(x, new ArrayList<>());
int y = in.readInt();
yMap.putIfAbsent(y, new ArrayList<>());
xMap.get(x).add(y);
yMap.get(y).add(x);
}
int res = 0;
for (int x : xMap.keySet()) {
for (int y : xMap.get(x)) {
int horizontal = yMap.get(y).size() - 1;
int vertical = xMap.get(x).size() - 1;
res += horizontal * vertical;
}
}
System.out.println(res);
}
Spiegazione:
Per ogni stella, conto (oltre a me) quante altre stelle sono sullo stesso asse x e sullo stesso asse y, poi calcolo e aggiorno le posibili combinazioni.
Un aiutino?