# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35792 | 2017-11-30T08:12:28 Z | funcsr | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 2268 KB |
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 long long A, B; long long dp[20][10][10][3][2]; long long solve(string X) { rep(i, X.size()+1) rep(j, 10) rep(k, 10) rep(l, 3) rep(r, 2) dp[i][j][k][l][r] = 0; dp[0][0][0][0][0] = 1; rep(i, X.size()) { int ud = X[i]-'0'; rep(j, 10) { rep(k, 10) { rep(s, 3) { rep(r, 2) { if (dp[i][j][k][s][r] == 0) continue; rep(next, 10) { if (s == 1 && k == next) continue; if (s == 2 && (k == next || j == next)) continue; if (r == 0 && next > ud) continue; int ns = s; if (ns == 0) { if (next) ns++; } else if (ns == 1) ns++; dp[i+1][k][next][ns][r|(next<ud)] += dp[i][j][k][s][r]; } } } } } } long long s = 0; rep(i, 10) rep(j, 10) rep(k, 3) rep(r, 2) s += dp[X.size()][i][j][k][r]; return s; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> A >> B; long long s = solve(to_string(B)); if (A > 0) s -= solve(to_string(A-1)); cout << s << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2268 KB | Output is correct |
2 | Correct | 0 ms | 2268 KB | Output is correct |
3 | Correct | 0 ms | 2268 KB | Output is correct |
4 | Correct | 0 ms | 2268 KB | Output is correct |
5 | Correct | 0 ms | 2268 KB | Output is correct |
6 | Correct | 0 ms | 2268 KB | Output is correct |
7 | Correct | 0 ms | 2268 KB | Output is correct |
8 | Correct | 0 ms | 2268 KB | Output is correct |
9 | Correct | 0 ms | 2268 KB | Output is correct |
10 | Correct | 0 ms | 2268 KB | Output is correct |
11 | Correct | 0 ms | 2268 KB | Output is correct |
12 | Correct | 0 ms | 2268 KB | Output is correct |
13 | Correct | 0 ms | 2268 KB | Output is correct |
14 | Correct | 0 ms | 2268 KB | Output is correct |
15 | Correct | 0 ms | 2268 KB | Output is correct |
16 | Correct | 0 ms | 2268 KB | Output is correct |
17 | Correct | 0 ms | 2268 KB | Output is correct |
18 | Correct | 0 ms | 2268 KB | Output is correct |
19 | Correct | 0 ms | 2268 KB | Output is correct |
20 | Correct | 0 ms | 2268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2268 KB | Output is correct |
2 | Correct | 0 ms | 2268 KB | Output is correct |
3 | Correct | 0 ms | 2268 KB | Output is correct |
4 | Correct | 0 ms | 2268 KB | Output is correct |
5 | Correct | 0 ms | 2268 KB | Output is correct |
6 | Correct | 0 ms | 2268 KB | Output is correct |
7 | Correct | 0 ms | 2268 KB | Output is correct |
8 | Correct | 0 ms | 2268 KB | Output is correct |
9 | Correct | 0 ms | 2268 KB | Output is correct |
10 | Correct | 0 ms | 2268 KB | Output is correct |
11 | Correct | 0 ms | 2268 KB | Output is correct |
12 | Correct | 0 ms | 2268 KB | Output is correct |
13 | Correct | 0 ms | 2268 KB | Output is correct |
14 | Correct | 0 ms | 2268 KB | Output is correct |
15 | Correct | 0 ms | 2268 KB | Output is correct |
16 | Correct | 0 ms | 2268 KB | Output is correct |
17 | Correct | 0 ms | 2268 KB | Output is correct |
18 | Correct | 0 ms | 2268 KB | Output is correct |
19 | Correct | 0 ms | 2268 KB | Output is correct |
20 | Correct | 0 ms | 2268 KB | Output is correct |
21 | Correct | 0 ms | 2268 KB | Output is correct |
22 | Correct | 0 ms | 2268 KB | Output is correct |
23 | Correct | 0 ms | 2268 KB | Output is correct |
24 | Correct | 0 ms | 2268 KB | Output is correct |
25 | Correct | 0 ms | 2268 KB | Output is correct |
26 | Correct | 0 ms | 2268 KB | Output is correct |
27 | Correct | 0 ms | 2268 KB | Output is correct |
28 | Correct | 0 ms | 2268 KB | Output is correct |
29 | Correct | 0 ms | 2268 KB | Output is correct |
30 | Correct | 0 ms | 2268 KB | Output is correct |
31 | Correct | 0 ms | 2268 KB | Output is correct |
32 | Correct | 0 ms | 2268 KB | Output is correct |
33 | Correct | 0 ms | 2268 KB | Output is correct |
34 | Correct | 0 ms | 2268 KB | Output is correct |
35 | Correct | 0 ms | 2268 KB | Output is correct |
36 | Correct | 0 ms | 2268 KB | Output is correct |
37 | Correct | 0 ms | 2268 KB | Output is correct |
38 | Correct | 0 ms | 2268 KB | Output is correct |
39 | Correct | 0 ms | 2268 KB | Output is correct |
40 | Correct | 0 ms | 2268 KB | Output is correct |
41 | Correct | 0 ms | 2268 KB | Output is correct |
42 | Correct | 0 ms | 2268 KB | Output is correct |
43 | Correct | 0 ms | 2268 KB | Output is correct |
44 | Correct | 0 ms | 2268 KB | Output is correct |
45 | Correct | 0 ms | 2268 KB | Output is correct |