이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el "\n"
#define fio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
long long a,b;
long long dp[22][2][10][10][2][2];
int d[22],cnt;
int get_digits(long long n) {
cnt=0;
while(n) d[cnt++]=n%10,n/=10;
reverse(d,d+cnt);
return 0;
}
long long rec(int pos, int f, int before_last, int last, int has_before_last, int has_last) {
if(pos == cnt)
return has_last;
auto &ret = dp[pos][f][before_last][last][has_before_last][has_last];
if(ret != -1)
return ret;
ret = 0;
int i;
for(i=0;i<10;i++) {
if(f || i<=d[pos]){
if(!has_last || last!=i){
if(!has_before_last || before_last!=i) {
ret += rec(pos+1,f|(i<d[pos]),last,i,has_last,has_last|(i>0));
}
}
}
}
return ret;
}
long long f(long long n) {
get_digits(n);
memset(dp,-1,sizeof(dp));
return 1 + rec(0,0,0,0,0,0);
}
int main() {
fio
cin >> a >> b;
cout << f(b) - (a > 0 ? f(a-1):0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |