이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll // delete if causing problems
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+MOD)%MOD
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
const int maxn = 3e5+10; // change when needed!
const int MOD = 1e9+7; // same!
const int INF = 2e9;
const ll LINF = 4e18;
int n, m, x, y, l, r, k, q, t;
map<int, int> M, N;
string a, b;
int dp[20][12][12][2][2];
int recur(int pos=0, int last=10, int last2=10, bool sm=0, bool la=0)
{
if(pos==n) return dp[pos][last][last2][sm][la]=1;
if(dp[pos][last][last2][sm][la]!=-1) return dp[pos][last][last2][sm][la];
int start = 0, limit = 9, ans = 0;
if(!sm) limit = b[pos]-'0';
if(!la) start = a[pos]-'0';
for(int d = start; d <= limit; d++)
{
if(d==last or d==last2) continue;
bool SM = sm, LA = la;
if(!SM and d<limit) SM=true;
if(!LA and d>start) LA=true;
ans+=recur(pos+1, d, last, SM, LA);
}
return dp[pos][last][last2][sm][la]=ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> a >> b; n = (int)b.size(); memset(dp, -1, sizeof(dp));
cout << recur();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |