One possible reason is that the result does not fit in 32-bit integer and your maxn and min cause overflow
在2021年4月25日星期日 UTC-7 上午8:26:53<benzi...@gmail.com> 写道: > Can anyone please tell me what's wrong with this code? It's showing *RE *at > the *Test Set 2*. > > import java.util.Scanner; > import static java.lang.Math.max; > > public class Solution { > public static void main(String[] args) { > Scanner scan = new Scanner(System.in); > int tt, n, i, index, ans = 0; > int[] x = new int[100]; > n = scan.nextInt(); > for (tt = 1; tt <= n; tt++) { > ans = 0; > index = scan.nextInt(); > for (int j = 1; j <= index; j++) { > x[j] = scan.nextInt(); > } > for (int jj = 1; jj <= index; jj++) { > int min = x[jj]; > int maxn = x[jj]; > while (maxn <= x[jj - 1]) { > maxn = maxn * 10 + 9; > min = min * 10 + 0; > ans++; > } > x[jj] = max(x[jj - 1] + 1, min); > } > System.out.println("Case #" + tt + ": " + ans); > } > } > } > -- -- You received this message because you are subscribed to the Google Groups Code Jam group. To post to this group, send email to google-code@googlegroups.com. To unsubscribe from this group, send email to google-code+unsubscr...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/google-code?hl=en --- 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 google-code+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/102fa9db-5749-4059-88e8-b94fe61e0b92n%40googlegroups.com.