이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int len;
string upper;
// len-1, len-2, ... ,0
// 0, 1, ... len-1
ll dp[25][2][10][10];
ll calc(int i = 0, bool touch = 1, int p = -1, int pp = -1) {
if (i == len)return 1;
if (dp[i][touch][p][pp] != -1)return dp[i][touch][p][pp];
ll ret = 0;
if (touch) {
int uuu = upper[i] - '0';
for (int d = 0; d <= uuu; ++d) {
if (d == p || d == pp)continue;
ret += calc(i+1, d == uuu, d, p);
}
} else {
for (int d = 0; d < 10; ++d) {
if (d == p || d == pp)continue;
ret += calc(i+1, false, d, p);
}
}
return dp[i][touch][p][pp] = ret;
}
int main() {
ll a, b;
cin >> a >> b;
memset(dp, -1, sizeof dp);
upper = to_string(b);
len = upper.length();
ll ans = calc();
if (a > 1) {
memset(dp, -1, sizeof dp);
upper = to_string(a-1);
len = upper.length();
ans -= calc();
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |