이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
ll dp[20][2][11][11][2];
void reset() {
memset(dp,-1,sizeof(dp));
}
ll solve(string s, int i, bool lower, int l0, int l1, bool started) {
int n = s.length();
if (i == n) {
return started;
} else {
ll &res = dp[i][lower][l0][l1][started];
if (~res) return res;
res = 0;
//cout<<i<<": "<<lower<<" "<<l0<<" "<<l1<<" "<<started<<endl;
for (int d=0; d<=(lower?9:int(s[i]-'0')); d++) {
if (d==l0) continue;
if (d==l1) continue;
bool nlower = lower;
if (d<int(s[i]-'0')) nlower = true;
bool nstarted = started;
if (d>0) nstarted = true;
if (!nstarted) nlower = true;
int nl0 = l0;
int nl1 = l1;
if (nstarted) {
nl0 = l1;
nl1 = d;
}
res += solve(s, i+1, nlower, nl0, nl1, nstarted);
}
return res;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll a,b;
cin>>a>>b;
// [a,b]
reset();
ll res = solve(to_string(b),0,false,10,10,false);
reset();
if (a>0) {
res -= solve(to_string(a-1),0,false,10,10,false);
} else {
res++; //add 0
}
out(res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |