// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
int main() {
cin.tie(0)->sync_with_stdio(0);
string L, R; cin >> L >> R;
while(sz(L) < sz(R)) L = "0"+L;
ll ans = 0;
if (L == string(sz(L), '0')) {
L.back() = '1';
ans = 1;
}
function<ll(int, int, int, int, int, int)> DP = [&](int i, int gl, int lr, int nonz, int a, int b) {
// cout << i << " " << gl << " " << lr << " " << nonz << " " << a << " " << b << endl;
if (i == sz(L)) {
// cout << a << " " << b << endl;
return 1LL;
}
ll RES = 0;
for(int c = 0; c <= 9; c++) {
int ngl = (gl || c > (L[i]-'0'));
int nlr = (lr || c < (R[i]-'0'));
// cout << L[i] << " " << c << " " << R[i] << endl;
if (!gl && c < (L[i]-'0')) continue;
if (!lr && c > (R[i]-'0')) continue;
if (!nonz && c == 0) {
RES += DP(i+1, ngl, nlr, 0, -2, -1);
continue;
}
if (a == c || b == c) continue;
RES += DP(i+1, ngl, nlr, 1, b, c);
}
return RES;
};
ans += DP(0, 0, 0, 0, -2, -1);
cout << ans << nl;
exit(0-0);
}
/*
123456789 987654321
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
348 KB |
Time limit exceeded |
3 |
Execution timed out |
1074 ms |
348 KB |
Time limit exceeded |
4 |
Execution timed out |
1055 ms |
348 KB |
Time limit exceeded |
5 |
Correct |
151 ms |
432 KB |
Output is correct |
6 |
Correct |
140 ms |
592 KB |
Output is correct |
7 |
Correct |
9 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
348 KB |
Output is correct |
9 |
Correct |
11 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
348 KB |
Output is correct |
11 |
Correct |
15 ms |
348 KB |
Output is correct |
12 |
Correct |
85 ms |
436 KB |
Output is correct |
13 |
Correct |
23 ms |
348 KB |
Output is correct |
14 |
Correct |
150 ms |
348 KB |
Output is correct |
15 |
Correct |
172 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
1056 ms |
348 KB |
Time limit exceeded |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
1050 ms |
348 KB |
Time limit exceeded |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Execution timed out |
1082 ms |
348 KB |
Time limit exceeded |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Execution timed out |
1040 ms |
344 KB |
Time limit exceeded |
26 |
Execution timed out |
1022 ms |
344 KB |
Time limit exceeded |
27 |
Execution timed out |
1079 ms |
348 KB |
Time limit exceeded |
28 |
Execution timed out |
1049 ms |
348 KB |
Time limit exceeded |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Execution timed out |
1084 ms |
348 KB |
Time limit exceeded |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Execution timed out |
1081 ms |
348 KB |
Time limit exceeded |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Execution timed out |
1085 ms |
348 KB |
Time limit exceeded |
36 |
Execution timed out |
1048 ms |
348 KB |
Time limit exceeded |
37 |
Execution timed out |
1014 ms |
344 KB |
Time limit exceeded |
38 |
Execution timed out |
1026 ms |
344 KB |
Time limit exceeded |
39 |
Execution timed out |
1033 ms |
348 KB |
Time limit exceeded |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Execution timed out |
1037 ms |
344 KB |
Time limit exceeded |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Execution timed out |
1070 ms |
348 KB |
Time limit exceeded |
44 |
Execution timed out |
1044 ms |
344 KB |
Time limit exceeded |
45 |
Execution timed out |
1046 ms |
344 KB |
Time limit exceeded |