/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
#define int long long
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0 //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg arg,Args... args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here
int solve(int r) {
if (r <= 9)
return r + 1;
vint digits;
while (r) {
digits.pb(r % 10);
r /= 10;
}
reverse(digits.begin(), digits.end());
int n = sz(digits);
int ans = 0;
int dp[n][10][11]; //dp[i][j][k] - i-th digit; j-th cur digit; k-th cur previous digit.
for (int i = 0; i < n; i++) {
int prob1 = (i ? digits[i - 1] : 10),
prob2 = (i > 1 ? digits[i - 2] : 10);
//if (digits[i] == prob1 || digits[i] == prob2)
// break;
rep(j, 0, 10) {
rep(k, 0, 11)
dp[i][j][k] = 0;
if (digits[i] < j || (i + 1 < n && digits[i] == j))
continue;
if (j != prob1 && j != prob2)
rep(k, 0, 11)
dp[i][j][prob1] = 1;
}
int p = i + 1;
if (p != n) {
rep(j, 0, 10) {
rep(k, 0, 10) {
dp[p][j][k] = 0;
if (j != k)
rep(l, 0, 11)
if (l != j && l != k)
dp[p][j][k] += dp[p - 1][k][l];
}
}
p++;
for (; p < n; p++) {
rep(j, 0, 10) {
rep(k, 0, 10) {
dp[p][j][k] = 0;
if (j != k)
rep(l, 0, 10)
if (l != j && l != k)
dp[p][j][k] += dp[p - 1][k][l];
}
}
}
}
rep(j, 0, 10)
rep(k, 0, 10)
ans += dp[n - 1][j][k];
}
return ans;
}
void run() {
int a, b;
read(a, b);
put solve(b) - solve(a - 1);
}
int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
488 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
552 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
552 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
552 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
616 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
620 KB |
Output isn't correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
17 |
Correct |
2 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Incorrect |
3 ms |
760 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
760 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
820 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
820 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
856 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
856 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
856 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
856 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
896 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
896 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
896 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
896 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
896 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
21 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
904 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
904 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
904 KB |
Output isn't correct |
30 |
Incorrect |
4 ms |
904 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
904 KB |
Output isn't correct |
32 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
33 |
Incorrect |
2 ms |
904 KB |
Output isn't correct |
34 |
Incorrect |
2 ms |
904 KB |
Output isn't correct |
35 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
36 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
37 |
Incorrect |
3 ms |
904 KB |
Output isn't correct |
38 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
39 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
40 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
41 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
42 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
43 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
44 |
Incorrect |
3 ms |
992 KB |
Output isn't correct |
45 |
Incorrect |
2 ms |
992 KB |
Output isn't correct |