#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define FOR(a, b, c) for(int a=b;a <= c;++a)
#define pb push_back
#define int long long
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int oo = 1e9;
int n;
int f[20][11][11][2];
void add(int &x, int y) { x = (x + y); }
int solve(string maxn, int st) {
memset(f, 0, sizeof f);
f[0][0][0][0] = 1;
FOR(i, 0, 17) FOR(las2, 0, 9) FOR(las1, 0, 9) {
if(f[i][las2][las1][0]) {
int h = maxn[i] - '0';
FOR(t, 0, h) if((i <= st) || (i == st + 1 && t != las1) || (t != las1 && t != las2)) {
bool flag = 1;
if(t == h) flag = false;
add(f[i + 1][las1][t][flag], f[i][las2][las1][0]);
//cout << f[i + 1][las1][t][flag] << ' ' << flag << '\n';
}
}
if(f[i][las2][las1][1]) {
//cout << i << ' ' << las2 << ' ' << las1 << ' ' << f[i][las2][las1][1] << '\n';
FOR(t, 0, 9) if((i <= st) || (i == st + 1 && t != las1) || (t != las1 && t != las2)) {
add(f[i + 1][las1][t][1], f[i][las2][las1][1]);
}
}
}
// we need f[18][las1][las2][0]
int sum = 0;
FOR(i, 0, 9) FOR(j, 0, 9) add(sum, f[18][i][j][0]), add(sum, f[18][i][j][1]);
return sum;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int l, r; cin >> l >> r; l --;
string a = "", b = "";
while(l) a = char(l % 10 + 48) + a, l /= 10;
int sa = 18 - a.length();
while(a.length() < 18) a = "0" + a;
while(r) b = char(r % 10 + 48) + b, r /= 10;
int sb = 18 - b.length();
while(b.length() < 18) b = "0" + b;
//cout << b << ' ' << sb << ' ' << a << ' ' << sa << '\n';
cout << solve(b, sb) - solve(a, sa);// :D
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
292 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
500 KB |
Output isn't correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Incorrect |
2 ms |
500 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
500 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
2 ms |
640 KB |
Output is correct |
14 |
Incorrect |
2 ms |
640 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
640 KB |
Output isn't correct |
16 |
Correct |
2 ms |
704 KB |
Output is correct |
17 |
Correct |
3 ms |
704 KB |
Output is correct |
18 |
Correct |
2 ms |
704 KB |
Output is correct |
19 |
Correct |
2 ms |
704 KB |
Output is correct |
20 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
704 KB |
Output is correct |
2 |
Correct |
2 ms |
704 KB |
Output is correct |
3 |
Correct |
3 ms |
704 KB |
Output is correct |
4 |
Correct |
2 ms |
704 KB |
Output is correct |
5 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
11 |
Correct |
2 ms |
704 KB |
Output is correct |
12 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
704 KB |
Output isn't correct |
16 |
Correct |
2 ms |
704 KB |
Output is correct |
17 |
Correct |
2 ms |
704 KB |
Output is correct |
18 |
Correct |
2 ms |
704 KB |
Output is correct |
19 |
Correct |
2 ms |
704 KB |
Output is correct |
20 |
Correct |
2 ms |
704 KB |
Output is correct |
21 |
Correct |
2 ms |
704 KB |
Output is correct |
22 |
Correct |
2 ms |
704 KB |
Output is correct |
23 |
Correct |
2 ms |
704 KB |
Output is correct |
24 |
Correct |
2 ms |
704 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
2 ms |
704 KB |
Output is correct |
27 |
Correct |
2 ms |
704 KB |
Output is correct |
28 |
Correct |
2 ms |
704 KB |
Output is correct |
29 |
Correct |
2 ms |
704 KB |
Output is correct |
30 |
Correct |
2 ms |
704 KB |
Output is correct |
31 |
Correct |
2 ms |
704 KB |
Output is correct |
32 |
Correct |
2 ms |
704 KB |
Output is correct |
33 |
Correct |
2 ms |
704 KB |
Output is correct |
34 |
Correct |
2 ms |
704 KB |
Output is correct |
35 |
Correct |
2 ms |
704 KB |
Output is correct |
36 |
Correct |
2 ms |
704 KB |
Output is correct |
37 |
Correct |
2 ms |
704 KB |
Output is correct |
38 |
Correct |
2 ms |
704 KB |
Output is correct |
39 |
Correct |
2 ms |
704 KB |
Output is correct |
40 |
Correct |
2 ms |
704 KB |
Output is correct |
41 |
Correct |
2 ms |
704 KB |
Output is correct |
42 |
Correct |
2 ms |
704 KB |
Output is correct |
43 |
Correct |
2 ms |
704 KB |
Output is correct |
44 |
Correct |
2 ms |
704 KB |
Output is correct |
45 |
Correct |
2 ms |
704 KB |
Output is correct |