# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255603 | amoo_safar | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 392 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.
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 20;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll pw[N];
ll Solve(ll x){
if(x < 0) return 0;
if(x == 0) return 1;
vector<int> C;
while(x){
C.pb(x % 10);
x /= 10;
}
ll res = 1;
for(int i = 0; i < C.size() - 1; i++) res *= 10;
reverse(all(C));
for(int i = 0; i <= C.size(); i++){
if(i == C.size()){
res ++;
break;
}
if(i == 0){
if(C.size() == 1) res += C[0] - 1;
else res += (C[0] - 1) * 9ll * pw[C.size() - 2];
} else {
for(int j = 0; j < C[i]; j++){
if(j == C[i - 1]) continue;
if((i >= 2) && (j == C[i - 2])) continue;
res += pw[C.size() - i - 1];
}
}
if((i >= 1) && (C[i] == C[i - 1])) break;
if((i >= 2) && (C[i] == C[i - 2])) break;
}
return res;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
pw[0] = 1;
for(int i = 1; i < N; i++) pw[i] = 8 * pw[i - 1];
ll a, b;
cin >> a >> b;
cout << Solve(b) - Solve(a - 1) << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |