#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/freopen/"
ll dp[20][10][10];
ll calc(ll a)
{
if (a==-1)
return 0;
if (a<10)
return a+1;
vector <ll> num;
while (a>0)
{
num.pb(a%10);
a/=10;
}
reverse(num.begin(), num.end());
ll last=-1, last2=-1, last3=-1, ans=0, n=num.size();
for (ll i=0; i<num.size(); i++)
{
if ((last3==last || last2==last) && last!=-1)
break;
ll dig=num[i];
if (i==0)
{
for (ll j=1; j<dig; j++)
for (ll k=0; k<10; k++)
{
// cout << n-i << " " << j << " " << k << " " << dp[n-i][j][k] << "\n";
ans+=dp[n-i][j][k];
}
last3=last2; last2=last; last=dig;
continue;
}
if (i==1)
{
for (ll j=0; j<dig; j++)
{
// cout << n-i+1 << " " << last << " " << j << " " << dp[n-i+1][last][j] << "\n";
ans+=dp[n-i+1][last][j];
}
last3=last2; last2=last; last=dig;
continue;
}
for (ll j=0; j<=dig; j++)
if (j!=last2)
{
// cout << n-i+1 << " " << last << " " << j << " " << dp[n-i+1][last][j] << "\n";
ans+=dp[n-i+1][last][j];
}
last3=last2; last2=last; last=dig;
}
// cout << ans << " ";
for (ll i=1; i<n; i++)
{
if (i==1)
{
ans+=10;
continue;
}
for (ll j=1; j<10; j++)
for (ll k=0; k<10; k++)
{
// cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n";
ans+=dp[i][j][k];
}
}
// for (ll i=0; i<num.size(); i++)
// cout << num[i];
// cout << " ";
// cout << ans << "\n";
return ans;
}
int main()
{
#ifdef LOCAL
freopen( LOCALIO "input.txt","r",stdin) ;
freopen( LOCALIO "output.txt","w",stdout) ;
#endif
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// freopen("FIBONACCI.inp","r",stdin);
// freopen("FIBONACCI.out","w",stdout);
for (ll i=2; i<20; i++)
{
for (ll j=0; j<10; j++)
{
for (ll k=0; k<10; k++)
{
if (j==k)
{
dp[i][j][k]=0;
continue;
}
if (i==2)
{
dp[i][j][k]=1;
continue;
}
for (ll z=0; z<10; z++)
if (z!=j)
dp[i][j][k]+=dp[i-1][k][z];
// cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n";
}
}
}
ll a, b; cin >> a >> b;
cout << calc(b)-calc(a-1);
}
Compilation message
numbers.cpp: In function 'long long int calc(long long int)':
numbers.cpp:30:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (ll i=0; i<num.size(); i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
224 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
224 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
0 ms |
224 KB |
Output is correct |
15 |
Correct |
0 ms |
224 KB |
Output is correct |
16 |
Correct |
0 ms |
224 KB |
Output is correct |
17 |
Correct |
1 ms |
224 KB |
Output is correct |
18 |
Correct |
1 ms |
224 KB |
Output is correct |
19 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
224 KB |
Output is correct |
21 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
22 |
Correct |
1 ms |
224 KB |
Output is correct |
23 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
24 |
Correct |
1 ms |
220 KB |
Output is correct |
25 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Correct |
0 ms |
216 KB |
Output is correct |
33 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
34 |
Correct |
0 ms |
224 KB |
Output is correct |
35 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
38 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Incorrect |
1 ms |
220 KB |
Output isn't correct |
44 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |