이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long long
#define INF 1000000000
ll calc(string a, string 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];
}
}
}
return ans;
}
int main(){
unsigned ll a, b, ans = 0;
cin>>a>>b;
string str1 = "0", str2 = "9";
for (int i = 0; i < 20; i++){
unsigned ll nu1 = stoull(str1), nu2 = stoull(str2);
if (nu1 > b){
break;
}
if (nu2 < a){
str1 = "1" + str1, str2 = str2 + "9";
continue;
}
ans += calc(to_string(max(nu1, a)), to_string(min(nu2, b)));
str1 = "1" + str1, str2 = str2 + "9";
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |