# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778938 | ind1v | Palindrome-Free Numbers (BOI13_numbers) | C++11 | 1 ms | 340 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>
using namespace std;
long long a, b;
vector<int> d;
long long f[20][10][10][2][2][2];
long long dp(int pos, int nprv, int prv, bool nz, bool nnz, bool t) {
if (pos == d.size()) {
return 1;
}
long long &res = f[pos][nprv][prv][nz][nnz][t];
if (res != -1) {
return res;
}
res = 0;
int lim = t ? 9 : d[pos];
for (int i = 0; i <= lim; i++) {
if (nz && i == prv) {
continue;
}
if (nnz && i == nprv) {
continue;
}
res += dp(pos + 1, prv, i, nz || (i != 0), nz, t || (i < d[pos]));
}
return res;
}
long long solve(long long x) {
if (x < 0) {
return 0;
}
d.clear();
while (x > 0) {
d.emplace_back(x % 10);
x /= 10;
}
reverse(d.begin(), d.end());
memset(f, -1, sizeof(f));
return dp(0, 0, 0, 0, 0, 0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a >> b;
cout << solve(b) - solve(a - 1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |