# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112512 | 2019-05-20T11:26:52 Z | Kastanda | Palindrome-Free Numbers (BOI13_numbers) | C++11 | 3 ms | 512 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 19; ll dp[N], dp2[N], dp3[N]; ll Get(ll r) { if (r < 0) return (0); if (r <= 9) return (r + 1); ll m = r, len = 0; int A[N]; while (m) A[len ++] = m % 10, m /= 10; reverse(A, A + len); ll res = dp[len - 1]; for (int i = 0; i < len; i++) { for (int j = 0; j < A[i]; j++) { if (!i && !j) continue; if (i > 0 && j == A[i - 1]) continue; if (i > 1 && j == A[i - 2]) continue; if (i == 0) res += dp2[len - 1]; else res += dp3[len - i - 1]; } if (i > 0 && A[i] == A[i - 1]) return (res); if (i > 1 && A[i] == A[i - 2]) return (res); } if (A[len - 1] != A[len - 2] && (len == 2 || (A[len - 1] != A[len - 3]))) res ++; return (res); } int main() { dp[1] = 10; for (int i = 2; i < N; i++) dp[i] = dp[i - 1] * 8 + 11; dp2[0] = 1; dp2[1] = 9; for (int i = 2; i < N; i++) dp2[i] = dp2[i - 1] * 8; dp3[0] = 1; dp3[1] = 8; for (int i = 2; i < N; i++) dp3[i] = dp3[i - 1] * 8; ll l, r; scanf("%lld%lld", &l, &r); return !printf("%lld\n", Get(r) - Get(l - 1)); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 512 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 256 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 0 ms | 256 KB | Output is correct |
26 | Correct | 2 ms | 384 KB | Output is correct |
27 | Correct | 1 ms | 256 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 2 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 0 ms | 256 KB | Output is correct |
33 | Correct | 0 ms | 384 KB | Output is correct |
34 | Correct | 2 ms | 256 KB | Output is correct |
35 | Correct | 2 ms | 384 KB | Output is correct |
36 | Correct | 2 ms | 256 KB | Output is correct |
37 | Correct | 2 ms | 384 KB | Output is correct |
38 | Correct | 0 ms | 256 KB | Output is correct |
39 | Correct | 2 ms | 256 KB | Output is correct |
40 | Correct | 2 ms | 384 KB | Output is correct |
41 | Correct | 2 ms | 256 KB | Output is correct |
42 | Correct | 2 ms | 256 KB | Output is correct |
43 | Correct | 2 ms | 256 KB | Output is correct |
44 | Correct | 2 ms | 256 KB | Output is correct |
45 | Correct | 2 ms | 512 KB | Output is correct |