Submission #31879265
Source Code Expand
import java.util.*;
class Main {
public static void main(String[] args) {
var sc = new Scanner(System.in);
int n = sc.nextInt();
int inf = (int) 2e5;
var t = new long[inf + 1];
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
t[a]++;
}
var x = new long[inf + 1];
var y = new long[inf + 1];
Arrays.setAll(x, i -> t[i]);
Arrays.setAll(y, i -> t[i] * t[i]);
Arrays.parallelPrefix(x, Long::sum);
Arrays.parallelPrefix(y, Long::sum);
long ans = 0;
for (int i = 1; i <= inf; i++) {
ans += t[i] * (x[i - 1] * x[i - 1] - y[i - 1]) / 2;
}
System.out.println(ans);
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Distinct Trio |
| User | sounansya |
| Language | Java (OpenJDK 11.0.6) |
| Score | 400 |
| Code Size | 758 Byte |
| Status | AC |
| Exec Time | 558 ms |
| Memory | 61304 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 237 ms | 44492 KiB |
| random_02.txt | AC | 504 ms | 60600 KiB |
| random_03.txt | AC | 220 ms | 44456 KiB |
| random_04.txt | AC | 550 ms | 60980 KiB |
| random_05.txt | AC | 222 ms | 44608 KiB |
| random_06.txt | AC | 276 ms | 52432 KiB |
| random_07.txt | AC | 198 ms | 43272 KiB |
| random_08.txt | AC | 344 ms | 57836 KiB |
| random_09.txt | AC | 233 ms | 44436 KiB |
| random_10.txt | AC | 428 ms | 60048 KiB |
| random_11.txt | AC | 245 ms | 45144 KiB |
| random_12.txt | AC | 334 ms | 57700 KiB |
| random_13.txt | AC | 230 ms | 44312 KiB |
| random_14.txt | AC | 404 ms | 60852 KiB |
| random_15.txt | AC | 211 ms | 43216 KiB |
| random_16.txt | AC | 438 ms | 60980 KiB |
| random_17.txt | AC | 554 ms | 60160 KiB |
| random_18.txt | AC | 204 ms | 44748 KiB |
| random_19.txt | AC | 558 ms | 61304 KiB |
| random_20.txt | AC | 188 ms | 42704 KiB |
| sample_01.txt | AC | 201 ms | 44048 KiB |
| sample_02.txt | AC | 190 ms | 42984 KiB |
| sample_03.txt | AC | 200 ms | 43784 KiB |