#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ind(n) scanf("%d", &n)
#define ind2(n, m) scanf("%d%d", &n, &m)
#define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define inlld(n) scanf("%lld", &n)
#define inlld2(n, m) scanf("%lld%lld", &n, &m)
#define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
using namespace std;
const int N=105;
const int MOD=1e9+9;
typedef long long ll;
typedef long double ld;
ll n, m, digs[20], dp[20][12][12][2];
ll solve(ll dignum, ll last, ll last2, ll isless)
{
if(dignum<0 || last>11 || last2>11)
return 0;
if(dignum==0)
return 1;
if(dp[dignum][last][last2][isless]!=-1)
return dp[dignum][last][last2][isless];
if(!isless)
{
ll ret=0;
if(digs[dignum]!=last2 && digs[dignum]!=last)
ret+=solve(dignum-1, last, digs[dignum], 0);
for(int a=digs[dignum]-1; a>=0; a--)
if(a!=last2 && a!=last)
ret+=solve(dignum-1, last, a, 1);
return dp[dignum][last][last2][isless]=ret;
}
ll ret=0;
for(int a=9; a>=0; a--)
if(a!=last2 && a!=last)
ret+=solve(dignum-1, last, a, 1);
// printf("%lld %lld %lld %lld %lld\n", dignum, last, last2, isless, ret);
return dp[dignum][last][last2][isless]=ret;
}
ll double_solve(ll here)
{
ll x=here, a=1;
for(; x>0; a++)
{
digs[a]=x%10;
x/=10;
}
a--;
// for(ll b=1; b<=a; b++)
// printf("%lld ", digs[b]);
// printf("\n");
memset(dp, -1, sizeof(dp));
ll maxi=0;
for(ll b=digs[a]-1; b>0; b--)
maxi+=solve(a-1, b, 11, 1);
maxi+=solve(a-1, digs[a], 11, 0);
for(int b=a-1; b>0; b--)
for(int c=9; c>0; c--)
maxi+=solve(b-1, c, 11, 1);
return maxi;
}
int main()
{
inlld2(n, m);
ll maxi=double_solve(n-1);
ll mini=double_solve(m);
// printf("%lld %lld\n", maxi, mini);
printf("%lld\n", mini-maxi);
return 0;
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define inlld2(n, m) scanf("%lld%lld", &n, &m)
~~~~~^~~~~~~~~~~~~~~~~~~~
numbers.cpp:73:5: note: in expansion of macro 'inlld2'
inlld2(n, m);
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Incorrect |
2 ms |
416 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
420 KB |
Output isn't correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
612 KB |
Output is correct |
8 |
Correct |
3 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
2 ms |
628 KB |
Output is correct |
12 |
Correct |
3 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
636 KB |
Output is correct |
14 |
Incorrect |
2 ms |
644 KB |
Output isn't correct |
15 |
Correct |
2 ms |
676 KB |
Output is correct |
16 |
Incorrect |
2 ms |
696 KB |
Output isn't correct |
17 |
Correct |
2 ms |
700 KB |
Output is correct |
18 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
19 |
Incorrect |
3 ms |
708 KB |
Output isn't correct |
20 |
Correct |
2 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
716 KB |
Output is correct |
2 |
Incorrect |
3 ms |
720 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
732 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
740 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
740 KB |
Output isn't correct |
8 |
Correct |
2 ms |
744 KB |
Output is correct |
9 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
752 KB |
Output isn't correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Incorrect |
2 ms |
764 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Incorrect |
3 ms |
776 KB |
Output isn't correct |
17 |
Correct |
2 ms |
780 KB |
Output is correct |
18 |
Incorrect |
2 ms |
784 KB |
Output isn't correct |
19 |
Correct |
2 ms |
876 KB |
Output is correct |
20 |
Incorrect |
2 ms |
876 KB |
Output isn't correct |
21 |
Incorrect |
3 ms |
880 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
24 |
Correct |
2 ms |
880 KB |
Output is correct |
25 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
880 KB |
Output isn't correct |
29 |
Correct |
2 ms |
880 KB |
Output is correct |
30 |
Correct |
2 ms |
924 KB |
Output is correct |
31 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
32 |
Correct |
2 ms |
924 KB |
Output is correct |
33 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
34 |
Correct |
2 ms |
924 KB |
Output is correct |
35 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
36 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
37 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
38 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
39 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
40 |
Correct |
2 ms |
924 KB |
Output is correct |
41 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
42 |
Correct |
2 ms |
924 KB |
Output is correct |
43 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
44 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
45 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |