#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll dp[19][2][10][10][3];
vector<int> dig;
ll f(int x, int ok, int ld, int pld, int ds){
if(x==19)
return 1;
ll &mal = dp[x][ok][ld][pld][ds];
if(~mal)
return mal;
ll answer = 0;
for(int i = 0; i < 10; ++i){
if(!ok and i>dig[x])
continue;
if(ds>=1 and i==ld)
continue;
if(ds==2 and i==pld)
continue;
answer += f(x+1, ok|(i<dig[x]), i, ld, min(2, ds+(ds|(i!=0))));
}
return mal=answer;
}
ll plz(ll x){
if(x<0)
return 0;
dig.clear();
while(x)
dig.pb(x%10), x/=10;
while((int)dig.size()!=19)
dig.pb(0);
reverse(all(dig));
memset(dp, -1, sizeof dp);
return f(0, 0, 0, 0, 0);
}
int main(){
ll l, r;
scanf("%lld %lld", &l, &r);
ll answer = plz(r)-plz(l-1);
printf("%lld\n", answer);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'int main()':
numbers.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%lld %lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |