# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252183 | m3r8 | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 384 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 <stdio.h>
#include <vector>
#include <string.h>
#define ll long long
ll dp[10][10][20];
ll sm[20];
std::vector<int> num;
void con(ll a){
num.clear();
while(a){
num.push_back(a%10);
a /= 10;
};
};
ll calc(ll a){
if(a < 0)return 0;
if(a < 10)return a+1;
if(a < 100){
ll tmp = a/10;
if(tmp > a % 10)return a - tmp + 2;
else return a - tmp + 1;
};
con(a);
memset(dp,0,sizeof(dp));
memset(sm,0,sizeof(sm));
sm[1] = 10;
for(int i = 0;i<10;i++){
for(int j = 0;j<10;j++){
if(i != j){
dp[i][j][2] = 1;
};
if(i != 0){
sm[2] += dp[i][j][2];
};
};
};
for(int i = 3;i<20;i++){
for(int j = 0;j<10;j++){
for(int k = 0;k<10;k++){
for(int l = 0;l<10;l++){
if(j != k && j != l){
dp[j][k][i] += dp[k][l][i-1];
};
};
if(j != 0){
sm[i] += dp[j][k][i];
};
};
};
};
ll erg = 0;
int prev = -1;
int pprev = -1;
for(int i = 0;i<num.size();i++){
int mx = num[num.size()-1-i];
int lf = num.size() - i;
if(lf >= 2){
int start = prev == -1 ? 1 : 0;
for(int j = start;j<mx;j++){
if(j != prev && j != pprev){
for(int k = 0;k<10;k++){
if(k != prev){
erg += dp[j][k][lf];
};
};
};
};
}else{
for(int j = 0;j<=mx;j++){
if(j != prev && j != pprev)erg++;
};
};
if(pprev == mx || prev == mx)break;
pprev = prev;
prev = mx;
};
for(int i = 1;i<num.size();i++){
erg += sm[i];
};
return erg;
};
int main(void){
ll a,b;
scanf("%lld %lld",&a,&b);
ll erg = calc(b) - calc(a-1);
printf("%lld\n",erg);
return 0;
};
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |