#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 |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
324 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
0 ms |
324 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
300 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |