# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798645 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 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;
#ifdef LOCAL
#include "/home/trucmai/.vim/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
void open(){
if(fopen("i.inp","r")){
freopen("i.inp","r",stdin);
freopen("o.out","w",stdout);
}
}
#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "
const int MN1 = 1e6 + 5,MN2 = 1e4 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll l,r,dp[20][11][11][2]; vi num;
ll f(ll i,ll d1,ll d2,bool tight){
if(i == num.size()) return 1;
ll &res = dp[i][d1+1][d2+1][tight];
if(~res) return res;
res = 0; ll lim = (tight ? 9 : num[i]);
for(ll digit = 0;digit <= lim;++digit){
if(digit == d1 || digit == d2) continue;
res += f(i+1,d2,((d2 == -1) && (digit == 0) ? -1 : digit),tight || (digit < lim));
}
return res;
}
ll calc(ll n){
if(n <= 0) return (n == 0);
num.clear();
while(n > 0) num.emplace_back(n % 10), n /= 10;
reverse(all(num));
mset(dp,-1);
return f(0,-1,-1,false);
}
void solve(){
cin>>l>>r;
cout<<calc(r) - calc(l-1);
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
open();
ll t = 1; //cin>>t;
while(t--) solve();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |