이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void print(__int128 x){
if ( x == 0 ) return;
print(x / 10);
cout << (int)(x % 10);
}
signed main(){
i64 a, b; cin >> a >> b;
auto f = [&](i64 x) -> __int128{
if ( x < 0 ) return 0;
string s = to_string(x);
int n = s.size();
for ( auto &x: s ) x -= '0';
__int128 dp[n][11][11][2]{};
for ( int j = 0; j <= s[0]; j++ ){
dp[0][10][j][j < s[0]] = 1;
}
for ( int i = 1; i < n; i++ ){
for ( int j = 0; j <= 10; j++ ){
for ( int k = 0; k <= 10; k++ ){
for ( int c = 0; c <= 9; c++ ){
if ( c == k || c == j ) continue;
for ( auto l: {0, 1} ){
if ( !l && c > s[i] ) continue;
int nxt = l || (c < s[i]);
dp[i][k][c][nxt] += dp[i - 1][j][k][l];
}
}
}
}
}
i64 cnt = 0;
for ( int x = 0; x <= 10; x++ ){
for ( int y = 0; y <= 10; y++ ){
for ( auto f: {0, 1} ){
cnt += dp[n - 1][x][y][f];
}
}
}
return cnt;
};
__int128 t = f(b) - f(a - 1);
if ( t == 0 ) cout << "0";
else print(t);
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |