# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082829 | lamlamlam | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 456 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][2],n;
string s;
int f(int pos,int tight,int prev1,int prev2,int started)
{
if(pos==n) return started;
if(dp[pos][tight][prev1][prev2][started]!=-1) return dp[pos][tight][prev1][prev2][started];
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);
int has_started = (started or i!=0);
res += f(pos+1,is_tight,i,prev1,has_started);
}
return dp[pos][tight][prev1][prev2][started] = res;
}
int sol(int x)
{
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][0] = dp[i][0][j][k][1] = dp[i][1][j][k][0] = dp[i][1][j][k][1] = -1;
s = to_string(x);
n = s.size();
return f(0,1,10,10,0);
}
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... |