이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define st first
#define nd second
#define ppii pair<pair<int,int>,pair<int, int>>
const int maxn = 2e5 + 5;
string t;
int a, b, dp[20][2][11][11][2];
int caldp(int pos, int eq, int lst1, int lst2, int start){
if(pos == t.size())
return 1;
if(dp[pos][eq][lst1][lst2][start] != -1)
return dp[pos][eq][lst1][lst2][start];
int ans = 0;
if(eq){
int limit = t[pos] - '0';
if(start){
for(int i = 0 ; i <= limit ; i++){
if(i == lst1 || i == lst2)
continue;
ans += caldp(pos + 1, (i == limit), i, lst1, start);
}
}
else{
for(int i = 1 ; i <= limit ; i++){
ans += caldp(pos + 1, (i == limit), i, -1, 1);
}
}
}
else{
if(start){
for(int i = 0 ; i <= 9 ; i++){
if(i == lst1 || i == lst2)
continue;
ans += caldp(pos + 1, 0, i, lst1, start);
}
}
else{
for(int i = 1 ; i <= 9 ; i++){
ans += caldp(pos + 1, 0, i, -1, 1);
}
}
}
return dp[pos][eq][lst1][lst2][start] = ans;
}
int prepdp(int x){
memset(dp, -1, sizeof dp);
t = to_string(x);
return caldp(0, 1, -1, -1, 0);
}
void solve(){
int a, b;
cin >> a >> b;
cout << prepdp(b) - prepdp(a - 1);
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp: In function 'long long int caldp(long long int, long long int, long long int, long long int, long long int)':
numbers.cpp:11:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | if(pos == t.size())
| ~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |