Submission #230671

# Submission time Handle Problem Language Result Execution time Memory
230671 2020-05-11T02:34:17 Z box_of_donuts Palindrome-Free Numbers (BOI13_numbers) Java 11
73.75 / 100
89 ms 11132 KB
import java.util.*;
import java.io.*;

public class numbers {
  private static String a, b;
  private static Long[][][][][] dp;
  
  private static long palRange(int i, int lst1, int lst2, int blo, int bhi) {
    if (dp[i][lst1+1][lst2+1][blo][bhi] != null) return dp[i][lst1+1][lst2+1][blo][bhi];
    if (i == a.length()) return dp[i][lst1+1][lst2+1][blo][bhi] = 1L;
    long ret = 0;
    for (int k = 0; k <= 9; k++) {
      if (k == lst1 || k == lst2) continue;
      if (blo == 1 && k < (a.charAt(i) - '0') || bhi == 1 && k > (b.charAt(i) - '0')) continue;
      ret += palRange(i+1, k, lst1, blo == 1 && k == (a.charAt(i) - '0') ? 1 : 0, 
                      bhi == 1 && k == (b.charAt(i) - '0') ? 1 : 0);
    }
    return dp[i][lst1+1][lst2+1][blo][bhi] = ret;
  }
  
  public static void main(String[] args) throws IOException { 
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    StringTokenizer ST = new StringTokenizer(in.readLine()); 
    a = ST.nextToken(); 
    b = ST.nextToken(); 
    
    while (a.length() < b.length()) a = "0" + a;
    dp = new Long[a.length()+1][11][11][2][2];
    long ans = palRange(0, -1, -1, 1, 1);
    out.println(ans);
  
    in.close();
    out.close();
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 10224 KB Output isn't correct
2 Incorrect 77 ms 10604 KB Output isn't correct
3 Correct 84 ms 10868 KB Output is correct
4 Incorrect 84 ms 10744 KB Output isn't correct
5 Correct 80 ms 10536 KB Output is correct
6 Incorrect 79 ms 10432 KB Output isn't correct
7 Incorrect 77 ms 10144 KB Output isn't correct
8 Incorrect 80 ms 10264 KB Output isn't correct
9 Correct 81 ms 10360 KB Output is correct
10 Correct 78 ms 10236 KB Output is correct
11 Correct 80 ms 10392 KB Output is correct
12 Correct 77 ms 10360 KB Output is correct
13 Correct 80 ms 10104 KB Output is correct
14 Incorrect 86 ms 10616 KB Output isn't correct
15 Incorrect 81 ms 10720 KB Output isn't correct
16 Correct 81 ms 10604 KB Output is correct
17 Correct 81 ms 10616 KB Output is correct
18 Correct 77 ms 10348 KB Output is correct
19 Correct 82 ms 10744 KB Output is correct
20 Incorrect 78 ms 10744 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 10764 KB Output is correct
2 Correct 84 ms 10776 KB Output is correct
3 Correct 82 ms 10868 KB Output is correct
4 Correct 82 ms 10740 KB Output is correct
5 Incorrect 84 ms 10612 KB Output isn't correct
6 Correct 86 ms 11000 KB Output is correct
7 Incorrect 86 ms 10696 KB Output isn't correct
8 Incorrect 86 ms 10872 KB Output isn't correct
9 Incorrect 86 ms 10616 KB Output isn't correct
10 Incorrect 81 ms 10616 KB Output isn't correct
11 Correct 78 ms 10856 KB Output is correct
12 Incorrect 83 ms 10748 KB Output isn't correct
13 Incorrect 83 ms 10772 KB Output isn't correct
14 Incorrect 82 ms 10744 KB Output isn't correct
15 Incorrect 82 ms 10872 KB Output isn't correct
16 Correct 83 ms 10776 KB Output is correct
17 Correct 82 ms 10504 KB Output is correct
18 Correct 82 ms 10628 KB Output is correct
19 Correct 83 ms 10360 KB Output is correct
20 Correct 80 ms 10612 KB Output is correct
21 Correct 85 ms 10756 KB Output is correct
22 Correct 80 ms 10744 KB Output is correct
23 Correct 85 ms 10772 KB Output is correct
24 Correct 81 ms 10616 KB Output is correct
25 Correct 86 ms 10868 KB Output is correct
26 Correct 85 ms 10788 KB Output is correct
27 Correct 82 ms 10872 KB Output is correct
28 Correct 88 ms 11132 KB Output is correct
29 Correct 83 ms 10612 KB Output is correct
30 Correct 78 ms 10744 KB Output is correct
31 Correct 82 ms 10872 KB Output is correct
32 Correct 77 ms 10616 KB Output is correct
33 Correct 84 ms 10868 KB Output is correct
34 Correct 79 ms 10556 KB Output is correct
35 Correct 85 ms 10612 KB Output is correct
36 Correct 89 ms 10744 KB Output is correct
37 Correct 84 ms 10576 KB Output is correct
38 Correct 84 ms 10740 KB Output is correct
39 Correct 84 ms 10776 KB Output is correct
40 Correct 81 ms 10488 KB Output is correct
41 Correct 83 ms 10772 KB Output is correct
42 Correct 80 ms 10612 KB Output is correct
43 Correct 85 ms 11016 KB Output is correct
44 Correct 85 ms 10900 KB Output is correct
45 Correct 86 ms 10988 KB Output is correct