# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961766 | marinaluca | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 0 ms | 0 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>
#pragma GCC optimize ("O4")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
using namespace std;
#define int long long
#define ll long long
#define XX first
#define YY second
#define all (x) begin(x), end(x)
/**
#define cin fin
#define cout fout
ifstream cin ("pfn.in");
ofstream cout ("pfn.out");
**/
typedef double dbl;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector <int> vii;
typedef pair <double, int> pdi;
vii v;
const int NMAX = 10;
const int VMAX = 1;
const int RMAX = 179;
int dp[2 * NMAX][RMAX + 1][VMAX + 1][VMAX + 1][VMAX + 1];
int constr (int val){
if (val < 10){
v.push_back(val);
return;
}
constr (val / 10);
v.push_back(val % 10);
}
int gigel (int i, int s, int t, int a, int b, int poz, int rez){
if (v.size() == i)
return true;
if (dp[i][s][t][a][b] == -1)
return dp[i][s][t][a][b];
int idx = 9, sum = 0;
if (t == 0)
idx = v[i];
for (int in = 0; in < idx; ++ in){
if (in == rez&& s) continue;
if (t && in == poz) continue;
sum += gigel (i + 1, s + in, a | (in < idx) , b | (in > 0) , ,rez , in);
}
return dp[i][s][t][a][b] = sum;
}
int solve (int a){
if (a == -1)
return 0;
v.clear();
constr (a);
memset (frec, -1, sizeof frec);
return gigel (0, 0, 0,0,0,0,0);
}
signed main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x, y;
cin >> x >> y;
cout << solve(y) - solve(x - 1);
return 0 ^ 0;
}