이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> num;
int dp[20][12][12][2];
//pos, last digit, last last digit, tight
//11 -> no digit
int call(int pos, int lst, int lslst, int f){
if (pos == num.size()){
return 1;
}
if (dp[pos][lst][lslst][f] != -1) return dp[pos][lst][lslst][f];
int res = 0;
int lmt = 0;
if (f == 0){
lmt = num[pos];
}
else{
lmt = 9;
}
for (int dgt = 0; dgt <= lmt; dgt++){
if (dgt == lst || dgt == lslst) continue;
int nf = f;
if (f == 0 && dgt < lmt) nf = 1;
res += call(pos+1,dgt,lst,nf);
}
return dp[pos][lst][lslst][f] = res;
}
int solve(int b){
num.clear();
while (b > 0){
num.push_back(b%10);
b /= 10;
}
reverse(num.begin(),num.end());
memset(dp,-1,sizeof(dp));
int res = call(0,11,11,0);
return res;
}
signed main() {
int a,b;
cin >> a >> b;
if (a != 0){
cout << solve(b)-solve(a-1);
}
else{
cout << solve(b)+1;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'long long int call(long long int, long long int, long long int, long long int)':
numbers.cpp:13:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (pos == num.size()){
| ~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |