이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |