This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3][25][15][15];
string tostr(ll n){
string s = "";
while(n){
s += '0' + (n%10);
n /= 10;
}
reverse(s.begin(), s.end());
return s;
}
ll solve(ll n){
for(int i=0; i<=20; i++){
for(int j=0; j<=10; j++){
for(int k=0; k<=10; k++){
for(int l=0; l<=10; l++){
dp[0][i][j][k] = dp[1][i][j][k] = dp[2][i][j][k] = 0;
}
}
}
}
dp[0][0][0][0] = 1;
string s = tostr(n);
int len = s.size();
for(int i=0; i<len; i++){
for(int j=0; j<=10; j++){
for(int k=0; k<=10; k++){
for(int l=1; l<=10; l++){
if(l == j || l == k) continue;
if(!i && l == 1) continue;
dp[1][i+1][k][l] += dp[1][i][j][k];
if(l-1 < s[i]-'0'){
dp[1][i+1][k][l] += dp[0][i][j][k];
}
if(l-1 == s[i]-'0'){
dp[0][i+1][k][l] += dp[0][i][j][k];
}
}
}
}
}
ll res = 0;
for(int i=0; i<=10; i++){
for(int j=0; j<=10; j++){
res += dp[0][len][i][j] + dp[1][len][i][j];
}
}
return res;
}
ll resi(ll n){
ll k = 0;
ll res = 0;
while(k < n){
res += solve(k);
k = 10*k+9;
}
res += solve(n);
return res;
}
int main(){
ios_base::sync_with_stdio(false);
ll a, b;
cin >> a >> b;
cout << resi(b) - resi(a-1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |