This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long long
#define INF 1000000000
int main(){
string a, b;
cin>>a>>b;
while (a.size() < b.size()){
a = "0" + a;
}
int n = b.size();
vector<vector<vector<vector<ll>>>> dp(n + 1, vector<vector<vector<ll>>>(10, vector<vector<ll>>(10, vector<ll>(4, 0))));
if (a[0] == b[0]){
dp[0][a[0] - '0'][a[0] - '0'][3] = 1;
}
else{
int st = a[0] - '0', en = b[0] - '0';
for (int i = st + 1; i < en; i++){
dp[0][i][i][0] = 1;
}
dp[0][st][st][1] = dp[0][en][en][2] = 1;
}
for (int i = 1; i < n; i++){
int st = a[i] - '0', en = b[i] - '0';
for (int j = 0; j < 10; j++){
for (int k = 0; k < 10; k++){
for (int l = 0; l < 4; l++){
for (int no = 0; no < 10; no++){
if (no == j || no == k) continue;
if (no < st && (l == 1 || l == 3)) continue;
if (no > en && (l == 2 || l == 3)) continue;
int ne = 0;
if (no == st && (l == 1 || l == 3)){
ne += 1;
}
if (no == en && (l == 2 || l == 3)){
ne += 2;
}
dp[i][k][no][ne] += dp[i - 1][j][k][l];
}
}
}
}
}
ll ans = 0;
for (int i = 0; i < 10; i++){
for (int j = 0; j < 10; j++){
for (int k = 0; k < 4; k++){
ans += dp[n - 1][i][j][k];
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |