이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
signed main() {
cin.tie(0)->sync_with_stdio(0);
string a, b;
cin >> a >> b;
string oa = a;
vector<vector<vector<vector<ll>>>> memo;
auto dp = [&](auto& dp, string& s, int i, char prev, char cur, bool free)->ll{
if (i == (int)s.size()) return 1;
ll& key = memo[free][i][prev][cur];
if (key != -1) return key;
ll res = 0;
for (char c = '0'; c <= '9'; c++) {
if (c == prev || c == cur) continue;
if (free || c <= s[i]) {
res += dp(dp, s, i+1, cur, c, free || c < s[i]);
}
}
return key = res;
};
auto calc = [&](string s) {
memo = vector(2, vector(s.size(), vector(128, vector(128, -1ll))));
return dp(dp, s, 0, '-', '-', false);
};
ll res = calc(b) - calc(a) + 1;
for (int i = 1; i < (int)a.size(); i++){
if (a[i] == a[i-1]) {res--; break; }
if (i >1 && a[i] == a[i-2]) {res--; break; }
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |