#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int lli;
const lli maxn = 20;
lli memo[maxn][12][12][2][2];
string A[2];
inline bool ispal(lli x, lli y, lli z) { return ((y == z) || (x == z)); }
lli DP(lli idx, lli prev, lli pprev, lli less, lli type)
{
if(idx == lli(A[type].size())) return 1;
else if(memo[idx][prev][pprev][less][type] != -1) return memo[idx][prev][pprev][less][type];
else
{
lli res = 0, val = (less?9:lli(A[type][idx]-'0'));
for(lli i = 0;i <= val;i++)
{
if(ispal(pprev, prev, i)) continue;
res += DP(idx+1, i, prev, max(less, lli(i < val)), type);
}
return memo[idx][prev][pprev][less][type] = res;
}
}
int main(void)
{
lli a, b;
scanf("%lld%lld", &a, &b);
A[0] = to_string(b), A[1] = to_string(a-1);
for(lli i = 0;i < maxn;i++)
{
for(lli j = 0;j < 11;j++)
{
for(lli k = 0;k < 11;k++)
{
for(lli l = 0;l < 2;l++) memo[i][j][k][l][0] = memo[i][j][k][l][1] = -1;
}
}
}
lli res = DP(0, 10, 10, 0, 0)-DP(0, 10, 10, 0, 1);
printf("%lld\n", res);
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:34:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a, &b);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
3 |
Correct |
0 ms |
2104 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
9 |
Correct |
0 ms |
2104 KB |
Output is correct |
10 |
Correct |
0 ms |
2104 KB |
Output is correct |
11 |
Correct |
0 ms |
2104 KB |
Output is correct |
12 |
Correct |
0 ms |
2104 KB |
Output is correct |
13 |
Correct |
0 ms |
2104 KB |
Output is correct |
14 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
16 |
Correct |
0 ms |
2104 KB |
Output is correct |
17 |
Correct |
0 ms |
2104 KB |
Output is correct |
18 |
Correct |
0 ms |
2104 KB |
Output is correct |
19 |
Correct |
0 ms |
2104 KB |
Output is correct |
20 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2104 KB |
Output is correct |
2 |
Correct |
0 ms |
2104 KB |
Output is correct |
3 |
Correct |
0 ms |
2104 KB |
Output is correct |
4 |
Correct |
0 ms |
2104 KB |
Output is correct |
5 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
6 |
Correct |
0 ms |
2104 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
11 |
Correct |
0 ms |
2104 KB |
Output is correct |
12 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
2104 KB |
Output isn't correct |
16 |
Correct |
0 ms |
2104 KB |
Output is correct |
17 |
Correct |
0 ms |
2104 KB |
Output is correct |
18 |
Correct |
0 ms |
2104 KB |
Output is correct |
19 |
Correct |
0 ms |
2104 KB |
Output is correct |
20 |
Correct |
0 ms |
2104 KB |
Output is correct |
21 |
Correct |
0 ms |
2104 KB |
Output is correct |
22 |
Correct |
0 ms |
2104 KB |
Output is correct |
23 |
Correct |
0 ms |
2104 KB |
Output is correct |
24 |
Correct |
0 ms |
2104 KB |
Output is correct |
25 |
Correct |
0 ms |
2104 KB |
Output is correct |
26 |
Correct |
0 ms |
2104 KB |
Output is correct |
27 |
Correct |
0 ms |
2104 KB |
Output is correct |
28 |
Correct |
0 ms |
2104 KB |
Output is correct |
29 |
Correct |
0 ms |
2104 KB |
Output is correct |
30 |
Correct |
0 ms |
2104 KB |
Output is correct |
31 |
Correct |
0 ms |
2104 KB |
Output is correct |
32 |
Correct |
0 ms |
2104 KB |
Output is correct |
33 |
Correct |
0 ms |
2104 KB |
Output is correct |
34 |
Correct |
0 ms |
2104 KB |
Output is correct |
35 |
Correct |
0 ms |
2104 KB |
Output is correct |
36 |
Correct |
0 ms |
2104 KB |
Output is correct |
37 |
Correct |
0 ms |
2104 KB |
Output is correct |
38 |
Correct |
0 ms |
2104 KB |
Output is correct |
39 |
Correct |
0 ms |
2104 KB |
Output is correct |
40 |
Correct |
0 ms |
2104 KB |
Output is correct |
41 |
Correct |
0 ms |
2104 KB |
Output is correct |
42 |
Correct |
0 ms |
2104 KB |
Output is correct |
43 |
Correct |
0 ms |
2104 KB |
Output is correct |
44 |
Correct |
0 ms |
2104 KB |
Output is correct |
45 |
Correct |
0 ms |
2104 KB |
Output is correct |