I declared a private record class within my solution to help solve one of the previous contest problems, but when I submit it to the analysis it says that it can’t find the symbol “record”, despite the code working correctly on my IDE. Is it due to the java version that the grader runs on?
Can you share the code?
Sure!
import java.util.*;
import java.io.*;
public class CircleCross {
record Pair(char a, char b) { // unordered pair implementation
public boolean equals(Object o) {
if (o instanceof Pair(char a1, char b1)) {
return (a == a1 && b == b1) || (a == b1 && b == a1);
}
return false;
}
public int hashCode() {
return a + b;
}
}
public static void main(String[] args) throws IOException{
String fileName = "file";
BufferedReader br = new BufferedReader(new FileReader(fileName +".in"));
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName +".out"));
char[] map = new char[52];
for (int i=0; i<52; i++) {
map[i] = (char) br.read();
}
HashSet<Pair> pairs = new HashSet<>();
HashSet<Character> charsChecked = new HashSet<>();
for (int i=0; i<52; i++) {
char cur = map[i];
int nextIndex = i+1;
if (charsChecked.contains(cur)) continue;
while (map[nextIndex] != cur) nextIndex++;
charsChecked.add(cur);
HashSet<Character> insideRange = new HashSet<>();
for (int j=i+1; j<nextIndex; j++) {
char testChar = map[j];
if (!insideRange.contains(testChar)) {
insideRange.add(testChar);
} else {
insideRange.remove(testChar);
}
}
for (char c : insideRange) {
pairs.add(new Pair(c, cur));
}
}
bw.write(pairs.size()+"");
bw.close();
}
}
Ok thanks, I see. It says that the grading servers run on Java version 11 which was before Records were added. Is there any possibility that USACO servers may be updated to support Java 17 or 21 in the future? (Since those are long-term support versions iirc)
That’s a question for the contest organizer (see the contact info on the instructions page). I haven’t heard anything about it.