# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
166380 | achibasadzishvili | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 10 ms | 508 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 ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll dp[25][12][12][3];
vector<ll>v;
ll solve(ll x){
if(x < 10)return x + 1;
ll xx = x;
v.clear();
while(x){
v.pb(x % 10);
x /= 10;
}
v.pb(-1);
reverse(v.begin() , v.end());
for(int i=0; i<=v.size(); i++)
for(int x=0; x<10; x++)
for(int y=0; y<=10; y++)
dp[i][x][y][0] = dp[i][x][y][1] = 0;
for(int x=1; x<10; x++)
for(int y=0; y<10; y++)
if(x != y || x == 0){
if(x < v[1] || (x == v[1] && y < v[2])){
dp[2][y][x][1] = 1;
}
if(x == v[1] && y == v[2])
dp[2][y][x][0] = 1;
}
for(int i=3; i<(int)v.size(); i++){
for(int n=0; n<10; n++)
for(int x=0; x<10; x++)
for(int y=0; y<10; y++){
if(x == y)continue;
if(n == x)continue;
if(n == y)continue;
dp[i][n][x][1] += dp[i - 1][x][y][1];
if(n < v[i])dp[i][n][x][1] += dp[i - 1][x][y][0];
if(n == v[i])dp[i][n][x][0] += dp[i - 1][x][y][0];
}
}
ll ret = 0;
ll n = (ll)v.size() - 1;
for(int x=0; x<10; x++)
for(int y=0; y<10; y++){
ret += dp[n][x][y][1] + dp[n][x][y][0];
}
return ret;
}
ll count(ll x){
ll ans = 0;
ans += solve(x);
ll raod = 0;
while(x){
raod++;
x /= 10;
}
ll p = 1;
for(int i=1; i<raod; i++){
p *= 10;
ans += solve(p - 1);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
ll x,y;
cin >> x >> y;
cout << count(y) - count(x - 1) << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |