#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define task ""
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
int n, a[N], dp[20][2][10][10][10];
int cal(int pos, bool tight, int x, int y, int z, int sum){
if(pos > n) return 1;
if(dp[pos][tight][x][y][z] != -1) return dp[pos][tight][x][y][z];
int &res = dp[pos][tight][x][y][z];
res = 0;
for(int i = 0; i <= (tight ? a[pos] : 9); i++){
if(i == z && sum) continue;
if(i == y && sum >= 10) continue;
res += cal(pos + 1, (tight & i == a[pos]), y, z, i, sum * 10 + i);
}
return res;
}
int sol(int x){
n = 0;
if(x == 0) return 0;
while(x){
a[++n] = x % 10;
x /= 10;
}
int l = 1, r = n;
while(l < r){
swap(a[l], a[r]);
l++; r--;
}
// for(int i = 1; i <= n; i++) cout << a[i];
// cout << '\n';
memset(dp, -1, sizeof dp);
return cal(1, 1, 10, 10, 10, 0);
}
main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(task ".inp", "r")){
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int a, b;
cin >> a >> b;
if(a == 0){
cout << sol(b);
return 0;
}
cout << sol(b) - sol(a - 1);
}
컴파일 시 표준 에러 (stderr) 메시지
numbers.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
numbers.cpp: In function 'int main()':
numbers.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(task ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |