julyydev / auto-judge

automatic compilation, execution, and I/O testing of online judge source code
https://www.npmjs.com/package/auto-judge
11 stars 1 forks source link

auto-judge failed to properly evaluate the accepted code on BOJ #5

Open ByeongsuPark opened 4 months ago

ByeongsuPark commented 4 months ago

Overview

auto-judge failed to properly evaluate the accepted code on BOJ. I believe that this is a issue related to the process of line breaking.

Details

When I submit the following code, it fails.

Click to see soruce code which fails ```java import java.util.*; import java.io.*; public class Main { private static final int NUM_MAX = 1_000_000; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); boolean[] isPrime = new boolean[NUM_MAX + 1]; isPrime[2] = true; for (int num = 1; num <= NUM_MAX; num++) isPrime[num] = true; isPrime[0] = false; isPrime[1] = false; // sieve of eratos for (int num = 2; num <= Math.sqrt(NUM_MAX); num++) { if (!isPrime[num]) continue; for (int numMul = num + num; numMul <= NUM_MAX; numMul += num) isPrime[numMul] =false; } StringTokenizer st = new StringTokenizer(br.readLine()); long answer = -1L; Set appeared = new HashSet<>(); for (int iter = 0; iter < n; iter++) { int num = Integer.parseInt(st.nextToken()); if (isPrime[num]) { if (answer != -1L && !appeared.contains((num))) { answer *= num; appeared.add(num); continue; } answer = num; appeared.add(num); } } bw.write(String.valueOf(answer)); bw.flush(); bw.close(); } } ```

As you can see, the expected and actual results are same. But auto-judge consider this as failed. Please note that BOJ accepts this code.

When I added newLine() after bw.write(...), auto-judge consider this code as valid. So, I believe that this is issue related to the process of line breaking

Click to see the code that passed. ```java import java.util.*; import java.io.*; public class Main { private static final int NUM_MAX = 1_000_000; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); boolean[] isPrime = new boolean[NUM_MAX + 1]; isPrime[2] = true; for (int num = 1; num <= NUM_MAX; num++) isPrime[num] = true; isPrime[0] = false; isPrime[1] = false; // sieve of eratos for (int num = 2; num <= Math.sqrt(NUM_MAX); num++) { if (!isPrime[num]) continue; for (int numMul = num + num; numMul <= NUM_MAX; numMul += num) isPrime[numMul] =false; } StringTokenizer st = new StringTokenizer(br.readLine()); long answer = -1L; Set appeared = new HashSet<>(); for (int iter = 0; iter < n; iter++) { int num = Integer.parseInt(st.nextToken()); if (isPrime[num]) { if (answer != -1L && !appeared.contains((num))) { answer *= num; appeared.add(num); continue; } answer = num; appeared.add(num); } } bw.write(String.valueOf(answer)); bw.newLine(); bw.flush(); bw.close(); } } ```