# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1176203 | quocbaoo | Palindrome-Free Numbers (BOI13_numbers) | C++20 | 1 ms | 328 KiB |
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
ll dp[18][11][11][2],a[20];
ll f(int n,int gh,int s1,int s2,int bd){
// cout<<n<<" "<<gh<<" "<<kt<<" "<<sl<<'\n';
if (n<0) {
return 1;
}
if (gh==0&&dp[n][s1][s2][bd]>=0) return dp[n][s1][s2][bd];
ll ans=0;int c=9;if (gh==1) c=a[n];
for (int i=0;i<=c;i++){
int ghm=0;if (gh==1&&i==c) ghm=1;
if (i==0&&bd==1){
ans+=f(n-1,ghm,s1,s2,1);continue;
}
if (i==s1||i==s2) continue;
ans+=f(n-1,ghm,s2,i,0);
}
if (gh==0) dp[n][s1][s2][bd]=ans;
return ans;
}
ll g(ll n){
int d=0;
while (n>0){
a[d]=n%10;d++;n/=10;
}
return f(d-1,1,10,10,1);
}
int main() {
if (fopen("MATRIX.INP","r")){
freopen("MATRIX.INP","r",stdin);
freopen("MATRIX.OUT","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
memset(dp,-1,sizeof(dp));
ll a,b;cin>>a>>b;
cout<<g(b)-g(a-1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |