| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1120611 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 ms | 512 KiB |
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>
#define ll long long
#define mein ios::base_sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll dp[10][10][20][2];
string str;
ll cal(int f, int s, int len, bool l){
if(len >= str.length()){
return 1;
}
else{
if(dp[f][s][len][l] == -1){
ll check = 0;
if(l){
for(int i = 0; i <= 9; ++i){
if(i != f && i != s){
check +=cal(s,i,len+1,true);
}
}
}
else{
int border = str[len] - '0';
for(int i = 0; i < border; ++i){
if(i != f && i != s){
check +=cal(s,i,len+1,true);
}
}
if(border != f && border != s){
check += cal(s,border,len+1,false);
}
}
dp[f][s][len][l] = check;
}
return dp[f][s][len][l];
}
}
ll memory(ll num){
if(num < 0) return 0;
stringstream ss; ss << num;
str = ss.str();
memset(dp, -1, sizeof(dp));
int f = str[0] - '0';
ll ans = 1;
for(int i = 1; i <= f; ++i){
ans += cal(i,i,1,i != f);
}
for(int j = 2; j <= str.length(); ++j){
for(int i = 1; i < 10; ++i){
ans += cal(i,i,j,true);
}
}
return ans;
}
int main(){
ll a,b;
cin >> a >> b;
ll x = memory(b) - memory(a-1);
cout << x << endl;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
