이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
using namespace std;
using i64 = long long;
template<typename T>
auto vectors(const int n, T&& val) {
return vector(n, val);
}
template<typename... Ts>
auto vectors(const int n, Ts&&... args) {
return vector(n, vectors(args...));
}
auto f = [](i64 n) {
if (n < 0) return 0LL;
string s = to_string(n);
vector dp = vectors(s.size(), 11, 11, 2, -1LL);
auto rec = [&](const auto& self, int i, int a, int b, int f) -> i64 {
if (i < 0) return 1;
i64& ret = dp[i][a][b][f];
if (ret != -1) return ret; ret = 0;
for (int x = 0; x < 10; x++) {
if (x == a || x == b) continue;
if (!f && x > s[s.size() - 1 - i] - 48) continue;
int nf = f || (x < s[s.size() - 1 - i] - 48);
ret += self(self, i - 1, b, x, nf);
}
return ret;
};
i64 res = 0;
for (int i = 0; i < s.size(); i++) {
int f = i + 1 < s.size();
res += rec(rec, i, 0, 10, f);
}
return res;
};
int main() {
fastio;
i64 a, b; cin >> a >> b;
cout << f(b) - f(a - 1) << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In lambda function:
numbers.cpp:24:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
24 | if (ret != -1) return ret; ret = 0;
| ^~
numbers.cpp:24:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
24 | if (ret != -1) return ret; ret = 0;
| ^~~
numbers.cpp: In lambda function:
numbers.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
numbers.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | int f = i + 1 < s.size();
| ~~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |