#include <bits/stdc++.h>
using namespace std;
long long dp[19][200][2];
long long mod =1e9 + 7;
string num;
int pal(string n) {
string y = n;
reverse(y.begin(), y.end());
return y == n;
}
int isok(string s) {
int sig = s.size();
for (int i = 0; i<s.size(); i++) {
if(s[i] != '0') {
sig = i;
break;
}
}
sig = 0;
for (int i = sig; i<s.size(); i++) {
string n = string(1, s[i]);
for (int j = i + 1; j<s.size(); j++) {
n += string(1, s[j]);
if(pal(n)) return 0;
}
}
return 1;
}
long long solve(int pos, long long cnt, int f,string s) {
if(!isok(s)) return 0;
if(pos == num.size()) {
return isok(s);
}
if(dp[pos][cnt][f] != -1) return dp[pos][cnt][f];
int lim = 9;
if(!f) lim = num[pos] - '0';
long long res = 0;
for (int i = 0; i<=lim; i++) {
res += solve(pos + 1, cnt + i, (i < lim || f), s + to_string(i));
}
return dp[pos][cnt][f] = res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long l, r;
cin >> l >> r;
l--;
num = to_string(l);
memset(dp, -1, sizeof(dp));
long long a1 = solve(0, 0, 0, "");
memset(dp, -1, sizeof(dp));
num = to_string(r);
cout << solve(0, 0, 0, "") - a1 << '\n';
return 0;
}
Compilation message
numbers.cpp: In function 'int isok(std::string)':
numbers.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i<s.size(); i++) {
| ~^~~~~~~~~
numbers.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = sig; i<s.size(); i++) {
| ~^~~~~~~~~
numbers.cpp:28:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int j = i + 1; j<s.size(); j++) {
| ~^~~~~~~~~
numbers.cpp: In function 'long long int solve(int, long long int, int, std::string)':
numbers.cpp:38:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if(pos == num.size()) {
| ~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Correct |
65 ms |
372 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
56 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
380 KB |
Output is correct |
2 |
Correct |
78 ms |
340 KB |
Output is correct |
3 |
Correct |
75 ms |
364 KB |
Output is correct |
4 |
Correct |
76 ms |
340 KB |
Output is correct |
5 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
11 |
Correct |
6 ms |
340 KB |
Output is correct |
12 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
16 |
Correct |
77 ms |
356 KB |
Output is correct |
17 |
Correct |
79 ms |
352 KB |
Output is correct |
18 |
Correct |
75 ms |
356 KB |
Output is correct |
19 |
Correct |
81 ms |
340 KB |
Output is correct |
20 |
Correct |
81 ms |
352 KB |
Output is correct |
21 |
Correct |
71 ms |
356 KB |
Output is correct |
22 |
Correct |
60 ms |
340 KB |
Output is correct |
23 |
Correct |
78 ms |
364 KB |
Output is correct |
24 |
Correct |
80 ms |
356 KB |
Output is correct |
25 |
Correct |
77 ms |
340 KB |
Output is correct |
26 |
Correct |
72 ms |
352 KB |
Output is correct |
27 |
Correct |
76 ms |
356 KB |
Output is correct |
28 |
Correct |
77 ms |
340 KB |
Output is correct |
29 |
Correct |
78 ms |
356 KB |
Output is correct |
30 |
Correct |
76 ms |
356 KB |
Output is correct |
31 |
Correct |
71 ms |
340 KB |
Output is correct |
32 |
Correct |
78 ms |
340 KB |
Output is correct |
33 |
Correct |
57 ms |
368 KB |
Output is correct |
34 |
Correct |
76 ms |
340 KB |
Output is correct |
35 |
Correct |
81 ms |
356 KB |
Output is correct |
36 |
Correct |
73 ms |
356 KB |
Output is correct |
37 |
Correct |
63 ms |
340 KB |
Output is correct |
38 |
Correct |
76 ms |
368 KB |
Output is correct |
39 |
Correct |
80 ms |
356 KB |
Output is correct |
40 |
Correct |
73 ms |
356 KB |
Output is correct |
41 |
Correct |
72 ms |
340 KB |
Output is correct |
42 |
Correct |
76 ms |
360 KB |
Output is correct |
43 |
Correct |
77 ms |
356 KB |
Output is correct |
44 |
Correct |
78 ms |
356 KB |
Output is correct |
45 |
Correct |
77 ms |
340 KB |
Output is correct |