-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuperbull.java
More file actions
53 lines (36 loc) · 1.2 KB
/
superbull.java
File metadata and controls
53 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.util.*;
public class superbull {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("superbull.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("superbull.out")));
int n = Integer.parseInt(f.readLine());
int[] teams = new int[n];
for(int i = 0; i<n;i++){
teams[i] = Integer.parseInt(f.readLine());
}
long result = 0;
boolean[] used = new boolean[n];
int[] edges = new int[n];
for (int i = 0; i < n; i++) {
int j = -1;
for (int k = 0; k < n; k++) {
if (used[k]) continue;
if (j == -1 || edges[k] > edges[j]) {
j = k;
}
}
result += edges[j];
used[j] = true;
for (int k = 0; k < n; k++) {
if(used[k]){
continue;
}
edges[k] = Math.max(edges[k], teams[j] ^ teams[k]);
}
}
out.println(result);
out.close();
}
}