# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
653989 | keitherrrr | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 416 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;
#define int long long
#define all(x) x.begin(), x.end()
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define FORd(i, a, b) for (int i=a-1; i>=b; i--)
#define F0R(i, a) for (int i=0; i<a; i++)
#define fi first
#define se second
#define be begin
#define e end
#define lb lower_bound
#define ub upper_bound
#define db long double
#define mid ((r+l)>>1)
#define tl (id<<1)
#define tr (id<<1|1)
const int N=20;
vi v;
int f[20][11][11][2], n;
int dp(int i,int val,int oldval,bool tight){
if(i>=n) return 1;
int &res=f[i][val][oldval][tight];
if(res!=-1) return res;
res=0;
int limit=(tight)?v[i]:9;
for(int d=0;d<=limit;d++)
if(d!=oldval&&d!=val){
int cur;
if(i==0&&d==0) cur=10;
else cur=d;
res+= dp(i+1,cur,val,tight&&d==limit);
}
return res;
}
int solve(string a){
v.clear();
memset(f,-1,sizeof(f));
FOR(i,0,a.size()) v.pb(a[i]-'0');
n=v.size();
return dp(0,10,10,1);
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
string a,b; cin >>a>>b;
int ans=solve(b)-solve(a);
bool g=0;
FOR(i,2,a.size()) if(a[i]==a[i-2]||a[i]==a[i-1]) {g=1; break;}
if(!g) ans++;
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |