# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121073 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 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 int ll
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 3e5 + 5; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const int mod = 998244353;
ll dp[18][11][11][2];
string s;
ll f(ll ind, ll prv1, ll prv2, bool ok){
if(ind == s.size()){
return 1;
}
if(dp[ind][prv1][prv2][ok] != -1){
return dp[ind][prv1][prv2][ok];
}
ll ans = 0;
for(int d = 0; d < 10; d++){
if(d == prv1 || d == prv2){continue;}
if(ok && d > (s[ind] - '0')){break;}
ll val = d;
if(val == 0 && prv1 == 10)val = 10;
if(d == (s[ind] - '0')){
ans += f(ind + 1, val, prv1, ok);
}
else{
ans += f(ind + 1, val, prv1, 0);
}
}
return dp[ind][prv1][prv2][ok] = ans;
}
void solve(){
ll a, b, i, j;
cin >> a >> b;
memset(dp, -1, sizeof(dp));
s = to_string(b);
ll r = f(0, 10, 10, 1);
if(!a){
cout << r << endl;
return ;
}
s = to_string(--a);
memset(dp, -1, sizeof(dp));
ll l = f(0, 10, 10, 1);
cout << r - l << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |