이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
long long dp[18][11][11];
string s;
long long rec(int i, int j, int k, bool lower, bool valid) {
if (i == 18) {
return valid;
}
if (dp[i][j][k] != -1 && lower && valid) {
return dp[i][j][k];
}
int m = lower ? 9 : s[i] - '0';
long long res = 0;
for (int c = 0; c <= m; ++c) {
if (c ^ j && c ^ k) {
bool lo = lower || c < m, ok = valid || c;
res += rec(i + 1, ok ? c : 10, j, lo, ok);
}
}
return lower && valid ? dp[i][j][k] = res : res;
}
long long calc(long long x) {
if (x < 0) {
return x;
}
s = to_string(x);
while (s.size() < 18) {
s = '0' + s;
}
return rec(0, 10, 10, 0, 0);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
long long a, b; cin >> a >> b;
memset(dp, -1, sizeof(dp));
cout << calc(b) - calc(a - 1);
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |