#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
const int DIGITS = 20;
const int LT = 0;
const int EQ = 1;
const int GT = 2;
ll dp[DIGITS][3][10][10];
bool check(string a) {
for (int i = 0; i < (int)a.size() - 1; i++) {
if (a[i] == a[i + 1]) {
return false;
}
}
for (int i = 0; i < (int)a.size() - 2; i++) {
if (a[i] == a[i + 2]) {
return false;
}
}
return true;
}
ll get(string a) {
if ((int)a.size() == 1) {
return a[0] - '0' + 1;
}
memset(dp, 0, sizeof(dp));
int n = (int)a.size();
for (int d1 = 1; d1 <= 9; d1++) {
for (int d2 = 0; d2 <= 9; d2++) {
if (d1 != d2) {
if (d1 * 10 + d2 < (a[0] - '0') * 10 + (a[1] - '0')) {
dp[2][LT][d1][d2]++;
}
else if (d1 * 10 + d2 == (a[0] - '0') * 10 + (a[1] - '0')) {
dp[2][EQ][d1][d2]++;
}
else {
dp[2][GT][d1][d2]++;
}
}
}
}
for (int i = 3; i <= n; i++) {
for (int d = 0; d <= 9; d++) {
for (int d1 = 0; d1 <= 9; d1++) {
for (int d2 = 0; d2 <= 9; d2++) {
if (d == d1 || d == d2 || d1 == d2) {
continue;
}
if (d < a[i - 1] - '0') {
dp[i][LT][d2][d] += dp[i - 1][LT][d1][d2];
dp[i][LT][d2][d] += dp[i - 1][EQ][d1][d2];
dp[i][GT][d2][d] += dp[i - 1][GT][d1][d2];
}
else if (d == a[i - 1] - '0') {
dp[i][LT][d2][d] += dp[i - 1][LT][d1][d2];
dp[i][EQ][d2][d] += dp[i - 1][EQ][d1][d2];
dp[i][GT][d2][d] += dp[i - 1][GT][d1][d2];
}
else {
dp[i][LT][d2][d] += dp[i - 1][LT][d1][d2];
dp[i][GT][d2][d] += dp[i - 1][GT][d1][d2];
dp[i][GT][d2][d] += dp[i - 1][EQ][d1][d2];
}
}
}
}
}
ll sol = 10;
for (int len = 2; len <= n; len++) {
for (int d1 = 0; d1 <= 9; d1++) {
for (int d2 = 0; d2 <= 9; d2++) {
sol += dp[len][LT][d1][d2] + dp[len][EQ][d1][d2];
if (len != n) {
sol += dp[len][GT][d1][d2];
}
}
}
}
return sol;
}
int main() {
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#else
FILE* stream;
freopen("input.txt", "r", stdin);
#endif
string a, b;
cin >> a >> b;
cout << get(b) - get(a) + check(a);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
500 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
544 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |