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 pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define TEXT "a"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
ll dp[20][11][11][2][2];
string s;
int n;
string conv(ll x){
string res = "";
if (x == 0) return "0";
while(x){
res += (x % 10) + '0';
x /= 10;
}
reverse(all(res));
return res;
}
ll f(int pos,int l,int p,bool small,bool start){
//cout << pos << " " << l << " " << p << " " << small << " " << start << "\n";
if (pos == n) return 1;
ll &res = dp[pos][l][p][small][start];
if (res != -1) return res;
int num = s[pos] - '0';
res = 0;
for (int i = 0; i <= 9; i++){
bool nsmall = small | (i < num);
bool nstart = start | (i > 0);
if ((small == 0) && (i > num)) break;
if (start && (i == p || i == l)) continue;
if (nstart == 0) res += f(pos + 1,10,10,1,0);
else res += f(pos + 1,i,l,nsmall,nstart);
}
return res;
}
ll cal(ll x){
if (x < 0) return 0;
memset(dp,-1,sizeof(dp));
s = conv(x);
n = s.size();
return f(0,10,10,0,0);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".out","w",stdout);
}
ll a,b;
cin >> a >> b;
ll res = cal(b) - cal(a - 1);
cout << res << "\n";
return 0;
}
Compilation message (stderr)
numbers.cpp: In function 'int main()':
numbers.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(TEXT".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(TEXT".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |