#include <bits/stdc++.h>
using namespace std;
typedef double dd;
typedef long long ll;
ll k;
ll dp[20][11][11][2][2];
vector <int> convert(ll x)
{
vector <int> v;
if (x == 0)
{
v.push_back(0);
return v;
}
while (x)
{
v.push_back(x % 10 + 1);
x /= 10;
}
reverse(v.begin(), v.end());
return v;
}
ll calc(const vector <int> &v, ll n, ll prev2, ll prev1, ll k0, ll f)
{
// cout << n << " " << s << " " << f <<"\n";
if (n == v.size())
{
return 1;
}
if (dp[n][prev2][prev1][k0][f] != -1) return dp[n][prev2][prev1][k0][f];
int lim;
if (f == 1) lim = 10;
else lim = v[n];
// cout << v[n] << "\n";
ll res = 0;
for (int i = 1; i <= lim; ++i)
{
int nf = f;
if (i <lim) nf = 1;
int nk0 = k0;
if (i > 1) nk0 = 1;
if (k0 == 0 && i == 1)
{
res += calc(v, n + 1, prev2, prev1, k0, nf);
continue;
}
if (prev2 != 0 && prev1 != 0 && i == prev2) continue;
if (prev1 != 0 && i == prev1) continue;
res += calc(v, n + 1, prev1, i, nk0, nf);
}
return dp[n][prev2][prev1][k0][f] = res;
}
ll solve(ll x)
{
if (x <= 10) return x;
if (x <= 100) return x - x / 11;
for (ll i = 0; i < 20; ++i)
for (ll j = 0; j < 11; ++j)
for (ll z = 0; z < 11; ++z)
for (ll t = 0; t < 2; ++t)
for (ll t1 = 0; t1 < 2; ++t1) dp[i][j][z][t][t1] = -1;
vector <int> v = convert(x);
return calc(v, 0, 0, 0, 0, 0);
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("input.inp", "r", stdin);
// freopen("output.out", "w", stdout);
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; ++i)
{
ll a, b;
cin >> a >> b >> k;
ll res1 = solve(b);
ll res2 = solve(a - 1);
// cout << res1 << " " << res2 << '\n';
cout << res1 - res2 << "\n";
// cout <<"___----------------\n";
}
}
Compilation message
numbers.cpp: In function 'll calc(const std::vector<int>&, ll, ll, ll, ll, ll)':
numbers.cpp:31:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if (n == v.size())
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
368 KB |
Output isn't correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |