# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547250 | Jomnoi | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 ms | 360 KiB |
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>
#define DEBUG 0
using namespace std;
long long dp[20][2][11][11];
long long solve2(string s, int idx = 0, bool f = false, int p1 = 10, int p2 = 10) {
if(dp[idx][f][p1][p2] != -1) {
return dp[idx][f][p1][p2];
}
if(idx == s.size()) {
return 1;
}
int len = 9;
if(f == false) {
len = s[idx] - '0';
}
long long res = 0;
for(int i = 0; i <= len; i++) {
bool nf = f;
if(i < len) {
nf = true;
}
if(i == p1 or i == p2) {
continue;
}
res += solve2(s, idx + 1, nf, i, p1);
}
return dp[idx][f][p1][p2] = res;
}
long long solve(long long a) {
for(int i = 0; i < 20; i++) {
for(int j = 0; j <= 10; j++) {
for(int k = 0; k <= 10; k++) {
dp[i][0][j][k] = dp[i][1][j][k] = -1;
}
}
}
string t;
while(a > 0) {
t.push_back(a % 10 + '0');
a /= 10;
}
reverse(t.begin(), t.end());
return solve2(t);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
long long a, b, ans;
cin >> a >> b;
ans = solve(b);
if(a > 0) {
ans -= solve(a - 1);
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |