It is stated in the FAQ
"Anything your program sends through standard error is ignored, but it might
consume some memory and be counted against your memory limit, so do not
overflow it. "
So as far as we don't output too much in the standard error, it should be fine,
right?
For debugging purpose, I print the exchanges of the interactive problems (so
the standard in and out) on the standard error. I do this because the local
interactive runner doesn't print the exchanges and then it's really hard to
understand what is going on. By the way if anybody know how to change it
directly in the runner, I would ne interested (I don't know much python).
But it seems that both the online juge and the interactive runner cannot handle
the standard error. For the interactive runner it gets stuck and the online
juge gives me a TLE. I had created a switch for that and forgot to switch it
off, and I spent some time trying to understand what was wrong. I never thought
that the reason was that I was printing on the standard error since the FAQ
said that this was ok. (and I finished 1501 because of that, which is kind of
sad).
I don't understand because it's not like what I am printing is huge since it's
only the exchanges.
Here is my code for "Power Arranger" of 2019 Round 1C. You can try ourself, if
the switch "err" is set to true, I get a TLE but everything works well if it is
set to false:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Solution {
private static boolean err = true;
private final Scanner sc;
public static final Set<Character> letters = createLetterSet();
private List<String> myComb;
private int asked = 0;
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new
InputStreamReader(System.in)));
String s = read(in);
int[] line = lineToInt(s, " ");
int t = line[0];// Scanner has functions to read ints, longs, strings,
chars, etc.
for (int i = 1; i <= t; ++i) {
Solution solution = new Solution(in);
solution.solve();
}
}
private static HashSet<Character> createLetterSet() {
char[] letters = {'A','B','C', 'D', 'E'};
HashSet<Character> remaining = new HashSet<>();
for (char letter : letters) {
remaining.add(letter);
}
return remaining;
}
private void solve() {
Set<Integer> remaining = IntStream.range(0,
119).boxed().collect(Collectors.toSet());
char[] result = new char[5];
Map.Entry<Character, Set<Integer>> entry = getNextSet(remaining, 24, 0);
result[0] = entry.getKey();
entry = getNextSet(entry.getValue(), 6, 1);
result[1] = entry.getKey();
entry = getNextSet(entry.getValue(), 2, 2);
result[2] = entry.getKey();
entry = getNextSet(entry.getValue(), 0, 3);
result[3] = entry.getKey();
result[4] = findMissing(result);
char t = result[3];
result[3] = result[4];
result[4] = t;
print(new String(result));
if(read(sc).equals("N")){
throw new RuntimeException("hoho");
}
}
private Map.Entry<Character, Set<Integer>> getNextSet(Set<Integer>
valuesToCheck, int expectedValue, int i) {
Map<Character, Set<Integer>> map = new HashMap<>();
for (Integer c : valuesToCheck) {
print(1+ i+c * 5 + "");
String result = read(sc);
char letter = result.charAt(0);
if (map.containsKey(letter)) {
map.get(letter).add(c);
} else {
map.put(letter, new HashSet<>());
map.get(letter).add(c);
}
}
for (Map.Entry<Character, Set<Integer>> entry : map.entrySet()) {
if(entry.getValue().size() != expectedValue){
return entry;
}
}
throw new RuntimeException();
}
private char findMissing(char[] team) {
HashSet<Character> remaining = new HashSet<>(letters);
for (int i = 0; i < 4; i++) {
remaining.remove(team[i]);
}
return remaining.iterator().next();
}
public Solution(Scanner sc) {
this.sc = sc;
}
private void print(String s) {
System.out.println(s);
if (err){
System.err.println("out: " + s);
}
System.out.flush();
}
private static String read(Scanner sc) {
String s = sc.nextLine();
if (err){
System.err.println("in: " + s);
}
return s;
}
public static int[] lineToInt(String line, String regex) {
return
Stream.of(line.split(regex)).mapToInt(Integer::parseInt).toArray();
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/59ba58cc-8300-4b1d-9235-6d18208cd6ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.