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;
#define REP(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i = a; i<=b; i++)
#define FORD(i, a, b) for(ll i = a; i>=b; i--)
#define DEBUG(x) cout<<#x<<" > "<<x<<endl;
#define endl '\n'
const ll MOD = 1e9 + 7, INF = 1e18, MX = 1e5 + 4;
ll a, b;
string s;
ll dp[20][2][11][11];
ll f(ll idx, bool b, ll pree, ll pre)
{
if(idx == s.size())
return 1;
if(pre == pree && pre != 10)
return 0;
if(dp[idx][b][pree][pre] != -1)
return dp[idx][b][pree][pre];
ll ans = 0;
FOR(i, 0, 9)
{
if(b == 0 && i < s[idx] - '0' && i != pree && i != pre)
{
ans += f(idx + 1, 1, pre, i);
}
if(b == 0 && i == s[idx] - '0' && i != pree && i != pre)
{
ans += f(idx + 1, 0, pre, i);
}
if(b == 1 && i != pre && i != pree)
{
ans += f(idx + 1, 1, pre, i);
}
}
return dp[idx][b][pree][pre] = ans;
}
int main()
{
memset(dp, -1, sizeof(dp));
cin >> a >> b;
a--;
s = to_string(a);
ll ff = f(0, 0, 10, 10);
s = to_string(b);
memset(dp, -1, sizeof(dp));
ll fff = f(0, 0, 10, 10);
cout << fff - ff << endl;
}
Compilation message (stderr)
numbers.cpp: In function 'll f(ll, bool, ll, ll)':
numbers.cpp:20:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(idx == s.size())
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |