# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723788 | Juan | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 304 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>
using namespace std;
#define int long long
int solve(int n){
if(n<10) return n+1;
if(n<100) return n+1 - n/11;
int rt = 81;
string s = to_string(n);
rt *= pow(8, max(0LL, (int)s.size()-3));
rt += (s[0]-'0'-1) * 9 * pow(8, s.size()-2);
for(int i = 1; i < s.size(); i++){
int niii=10;
int ni = s[i]-'0';
int nii = s[i-1]-'0';
if(i>=2) niii = s[i-2]-'0';
rt += max(ni -(nii<ni) -(niii<ni), 0LL) * pow(8, max(0LL, (int)s.size()-i-1));
if((i>=1 && s[i]==s[i-1]) || (i>=2 && s[i]==s[i-2])) break;
if(i==s.size()-1) rt++;
}
return rt;
}
int32_t main(){
int a, b; cin >> a >> b;
cout << solve(b) - solve(a-1) << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |