#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.size() - 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 = 9;
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;
ll nra = 0, nrb = 0;
for (int i = 0; i < (int)a.size(); i++) {
nra = nra * 10 + a[i] - '0';
nrb = nrb * 10 + b[i] - '0';
}
if (nrb - nra <= 100000) {
ll sol = 0;
for (int i = nra; i <= nrb; i++) {
string s = "";
int j = i;
while (j) {
s += (char) ('0' + j % 10);
j /= 10;
}
reverse(s.begin(), s.end());
sol += check(s);
}
cout << sol << "\n";
return 0;
}
cout << get(b) - get(a) + check(a);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Execution timed out |
1058 ms |
348 KB |
Time limit exceeded |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Correct |
0 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
1095 ms |
348 KB |
Time limit exceeded |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 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 |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 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 |