This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
cout << s << '\n';
for (int i = 0; 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;
if(l > r) swap(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 (stderr)
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:21:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | 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:31:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if(pos == num.size()) {
| ~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |