제출 #230671

#제출 시각아이디문제언어결과실행 시간메모리
230671box_of_donutsPalindrome-Free Numbers (BOI13_numbers)Java
73.75 / 100
89 ms11132 KiB
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...