#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[30][10][10][3][3];
string a, b;
ll solve(int pos, int d1, int d2, int m1, int m2)
{
if (pos == b.size()) return 0;
if (dp[pos][d1][d2][m1][m2] != -1) return dp[pos][d1][d2][m1][m2];
ll ans = 0LL;
for (int i = 0; i <= 9; i++)
{
if ((!i && !pos) || (i == d1 && pos >= 2) || (i == d2 && pos >= 1)) continue;
int n1 = 2;
if (!m1) n1 = 0;
else if (m1 == 1) n1 = 1;
else if (i < (int)a[pos]-'0') n1 = 0;
else if (i > (int)a[pos]-'0') n1 = 1;
int n2 = 2;
if (!m2) n2 = 0;
else if (m2 == 1) n2 = 1;
else if (i < (int)b[pos]-'0') n2 = 0;
else if (i > (int)b[pos]-'0') n2 = 1;
int add = 0;
if (a.size() == b.size() && pos == a.size()-1)
{
if (n1 && n2 != 1) add = 1;
else add = 0;
}
else if (pos == a.size()-1 && n1) add = 1;
else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
else if (pos == b.size()-1 && n2 != 1) add = 1;
ans += (ll)add+solve(pos+1, d2, i, n1, n2);
}
return dp[pos][d1][d2][m1][m2] = ans;
}
int main(void)
{
memset(dp, -1, sizeof dp);
cin >> a >> b;
int add = (a[0] == '0' ? 1 : 0);
cout << add+solve(0, 0, 0, 2, 2) << "\n";
}
Compilation message
numbers.cpp: In function 'll solve(int, int, int, int, int)':
numbers.cpp:13:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pos == b.size()) return 0;
~~~~^~~~~~~~~~~
numbers.cpp:35:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (a.size() == b.size() && pos == a.size()-1)
~~~~^~~~~~~~~~~~~
numbers.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (pos == a.size()-1 && n1) add = 1;
~~~~^~~~~~~~~~~~~
numbers.cpp:41:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
~~~~^~~~~~~~~~~~
numbers.cpp:41:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
~~~~^~~~~~~~~~~~
numbers.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (pos == b.size()-1 && n2 != 1) add = 1;
~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
3 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
512 KB |
Output is correct |
35 |
Correct |
3 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
3 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
3 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
3 ms |
512 KB |
Output is correct |
44 |
Correct |
3 ms |
512 KB |
Output is correct |
45 |
Correct |
5 ms |
512 KB |
Output is correct |