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;
vector <int> Digit;
long long dp[20][2][2][11][11];
long long l, r;
long long F(int pos, int big, int start, int ppdigit, int pdigit)
{
if(pos == (int)Digit.size())
{
return 1;
}
long long &cur = dp[pos][big][start][ppdigit][pdigit];
if(cur != -1)
{
return cur;
}
cur = 0;
int can = (big ? 9 : Digit[pos]);
for(int nxtdigit = 0; nxtdigit <= can; nxtdigit++)
{
if(nxtdigit == pdigit or nxtdigit == ppdigit)
{
continue;
}
cur += F(pos + 1, big | (nxtdigit < Digit[pos]), start | (nxtdigit > 0), pdigit, (start | (nxtdigit > 0)) ? nxtdigit : 10);
}
return cur;
}
long long Count(long long x)
{
if(x < 0)
{
return 0;
}
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 2; j++)
{
for(int k = 0; k < 2; k++)
{
for(int l = 0; l < 11; l++)
{
for(int h = 0; h < 11; h++)
{
dp[i][j][k][l][h] = -1;
}
}
}
}
}
Digit.clear();
while(x)
{
Digit.push_back(x % 10);
x /= 10;
}
reverse(Digit.begin(), Digit.end());
return F(0, 0, 0, 10, 10);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> l >> r;
cout << Count(r) - Count(l - 1) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |