이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll memo[19][11][11][2][2];
ll dp(const string& s, int i, int p1, int p2, int tight, int lz)
{
if(i == s.size()) return 1;
ll& res = memo[i][p1][p2][tight][lz];
if(~res) return res;
res = 0;
if(tight) {
if(lz) {
res += dp(s, i + 1, 10, 10, 1, 1);
for(int c = 1; c < 10; ++c) res += dp(s, i + 1, 10, c, 1, 0);
}
else {
for(int c = 0; c < 10; ++c) {
if(c ^ p1 && c ^ p2) {
res += dp(s, i + 1, p2, c, 1, 0);
}
}
}
}
else {
if(lz) {
res += dp(s, i + 1, 10, 10, s[i] > '0', 1);
for(int c = 1; c + 48 < s[i]; ++c) res += dp(s, i + 1, p2, c, 1, 0);
if(s[i] > '0' && s[i] ^ (p1 + 48) && s[i] ^ (p2 + 48)) res += dp(s, i + 1, p2, s[i] - 48, 0, 0);
}
else {
for(int c = 0; c + 48 < s[i]; ++c) {
if(c ^ p1 && c ^ p2) {
res += dp(s, i + 1, p2, c, 1, 0);
}
}
if(s[i] ^ (p1 + 48) && s[i] ^ (p2 + 48)) res += dp(s, i + 1, p2, s[i] - 48, 0, 0);
}
}
return res;
}
ll calc(ll i)
{
string s = to_string(i);
memset(memo, -1, sizeof(memo));
return dp(s, 0, 10, 10, 0, 1);
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
ll l, r; cin >> l >> r;
cout << calc(r) - (l ? calc(l - 1) : 0);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'll dp(const string&, int, int, int, int, int)':
numbers.cpp:10:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | if(i == s.size()) return 1;
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |