Submission #230674

# Submission time Handle Problem Language Result Execution time Memory
230674 2020-05-11T03:19:25 Z box_of_donuts Palindrome-Free Numbers (BOI13_numbers) Java 11
100 / 100
97 ms 11236 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 = -1; k <= 9; k++) {
      if (k == -1 && lst1 == -1 && a.charAt(i) == '#') ret += palRange(i+1, k, lst1, 1, 0);
      else if (k == -1) continue;
      if (k == 0 && lst1 == -1 && a.charAt(i) == '#' || 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 = "#" + 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 Correct 84 ms 10616 KB Output is correct
2 Correct 80 ms 10232 KB Output is correct
3 Correct 85 ms 10744 KB Output is correct
4 Correct 83 ms 10644 KB Output is correct
5 Correct 80 ms 10376 KB Output is correct
6 Correct 78 ms 10636 KB Output is correct
7 Correct 78 ms 10232 KB Output is correct
8 Correct 78 ms 10512 KB Output is correct
9 Correct 80 ms 10360 KB Output is correct
10 Correct 83 ms 10644 KB Output is correct
11 Correct 83 ms 10352 KB Output is correct
12 Correct 83 ms 10360 KB Output is correct
13 Correct 79 ms 10240 KB Output is correct
14 Correct 80 ms 10744 KB Output is correct
15 Correct 81 ms 10872 KB Output is correct
16 Correct 83 ms 10668 KB Output is correct
17 Correct 85 ms 10856 KB Output is correct
18 Correct 77 ms 10348 KB Output is correct
19 Correct 82 ms 10776 KB Output is correct
20 Correct 91 ms 10884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 11000 KB Output is correct
2 Correct 88 ms 11092 KB Output is correct
3 Correct 93 ms 10888 KB Output is correct
4 Correct 86 ms 10880 KB Output is correct
5 Correct 89 ms 10980 KB Output is correct
6 Correct 85 ms 10864 KB Output is correct
7 Correct 85 ms 10868 KB Output is correct
8 Correct 85 ms 11000 KB Output is correct
9 Correct 81 ms 11024 KB Output is correct
10 Correct 83 ms 10872 KB Output is correct
11 Correct 86 ms 10996 KB Output is correct
12 Correct 82 ms 10744 KB Output is correct
13 Correct 97 ms 10932 KB Output is correct
14 Correct 81 ms 10612 KB Output is correct
15 Correct 85 ms 10784 KB Output is correct
16 Correct 86 ms 10932 KB Output is correct
17 Correct 81 ms 10732 KB Output is correct
18 Correct 82 ms 10488 KB Output is correct
19 Correct 83 ms 10616 KB Output is correct
20 Correct 84 ms 10472 KB Output is correct
21 Correct 84 ms 11000 KB Output is correct
22 Correct 78 ms 10400 KB Output is correct
23 Correct 88 ms 11000 KB Output is correct
24 Correct 83 ms 10740 KB Output is correct
25 Correct 83 ms 11020 KB Output is correct
26 Correct 90 ms 11028 KB Output is correct
27 Correct 89 ms 10984 KB Output is correct
28 Correct 86 ms 11236 KB Output is correct
29 Correct 82 ms 10604 KB Output is correct
30 Correct 82 ms 10616 KB Output is correct
31 Correct 82 ms 10872 KB Output is correct
32 Correct 77 ms 10612 KB Output is correct
33 Correct 87 ms 10920 KB Output is correct
34 Correct 89 ms 10684 KB Output is correct
35 Correct 86 ms 10872 KB Output is correct
36 Correct 86 ms 10872 KB Output is correct
37 Correct 83 ms 11024 KB Output is correct
38 Correct 86 ms 10996 KB Output is correct
39 Correct 82 ms 11128 KB Output is correct
40 Correct 80 ms 10616 KB Output is correct
41 Correct 90 ms 11020 KB Output is correct
42 Correct 78 ms 10492 KB Output is correct
43 Correct 89 ms 11112 KB Output is correct
44 Correct 89 ms 11108 KB Output is correct
45 Correct 88 ms 11104 KB Output is correct