# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082826 | lamlamlam | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 600 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 endl '\n'
int a,b,dp[20][2][11][11],n;
string s;
int f(int pos,int tight,int prev1,int prev2)
{
if(pos==n) return 1;
if(dp[pos][tight][prev1][prev2]!=-1) return dp[pos][tight][prev1][prev2];
int res = 0, ub = 9;
if(tight) ub = s[pos] - '0';
for(int i=0; i<=ub; i++){
if(i==prev1 or i==prev2) continue;
int is_tight = (tight && i==ub);
res += f(pos+1,is_tight,i,prev1);
}
return dp[pos][tight][prev1][prev2] = res;
}
int sol(int x)
{
if(x<=9) return max(x,0ll);
for(int i=0; i<20; i++) for(int j=0; j<11; j++) for(int k=0; k<11; k++) dp[i][0][j][k] = dp[i][1][j][k] = -1;
s = to_string(x);
n = s.size();
return f(0,1,10,10);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "troll"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> a >> b;
cout << sol(b) - sol(a-1);
cerr << "\nTime: " << clock();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |