#include<bits/stdc++.h>
using namespace std;
#define int int64_t
const int64_t mod=1000000007;
namespace personal{
template<typename T>
int32_t sz(T x){return x.size();}
void equal(string &s,string &s1){
string ex(sz(s1)-sz(s),'0');
s=ex+s;
}
void equal(string &s,int x){
string ex(x-sz(s),'0');
s=ex+s;
}
void minus(string &s){
int32_t n=sz(s);
n--;
while(n+1 && s[n]=='0'){s[n]='9',n--;}
s[n]--;
}
void base_converter(int base,string &s,int x){
s.clear();
while(x){
s+=(char)((x%base)+'0');
x/=base;
}
reverse(s.begin(),s.end());
//cerr<<s<<"\n";
}
};
const int N=20,bl=2;
int cache[20][11][11][bl][bl][bl];
int n;
string s,s1;
int dp(int pos,int prv,int prv1,bool bigA,bool smallB,bool nonzero){
//cerr<<pos<<" "<<prv<<" "<<bigA<<" "<<smallB<<" "<<n<<"\n";
if (n==pos){
//cout<<p<<"\n";
return 1;
}
int &ans=cache[pos][prv1+1][prv+1][bigA][smallB][nonzero];
if (ans!=-1){return ans;}
ans=0;
for (int i=0;i<10;i++){
//cerr<<pos<<" "<<prv<<" "<<bigA<<" "<<smallB<<"\n";
if (!bigA && i<(s[pos]-'0')){continue;}
if (!smallB && i>(s1[pos]-'0')){continue;}
if (!nonzero && !i){
ans+=dp(pos+1,prv,prv1,bigA||(i>(s[pos]-'0')),smallB||(i<(s1[pos]-'0')),nonzero||i);
continue;
}
if (prv!=i && prv1!=i){
ans+=dp(pos+1,prv1,i,bigA||(i>(s[pos]-'0')),smallB||(i<(s1[pos]-'0')),nonzero||i);
}
}
return ans;
}
void solve(int fuck){
cin>>s>>s1;
//cerr<<s<<" "<<s1;
memset(cache,-1,sizeof(cache));
personal::equal(s,s1);
n=personal::sz(s1);
cout<<dp(0,-1,-1,0,0,0);
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int tq=1;
//cin>>tq;
for (int i=1;i<=tq;i++){
solve(i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
480 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
396 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
464 KB |
Output is correct |
42 |
Correct |
0 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |