| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 49008 | Namnamseo | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 4 ms | 1008 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 sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define coord_comp(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define v_index(v, x) (lower_bound(all(v),x)-(v).begin())
typedef pair<int,int> pp;
typedef long long ll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T1,typename T2>
void read(pair<T1,T2>& p){ read(p.first); read(p.second); }
template<typename T,typename... Args>
void read(T&a,Args&...b){ read(a); read(b...); }
char s[50];
int sn;
ll f(ll x){
	sprintf(s, "%lld", x);
	for(sn=0; s[sn]; ++sn);
	ll ans = 0;
	for(int i=0; i<sn; ++i){
		int t = s[i]-'0';
		for(int j=0; j<t; ++j){
			if(i>=1 && s[i-1]-'0' == j) continue;
			if(i>=2 && s[i-2]-'0' == j) continue;
			if(i==0 && j==0){
				ll curS=0;
				for(int a=1; a<=sn; ++a){
					ll cur=1;
					for(int b=a; b<sn; ++b){
						if(b<=a+1) cur *= 9;
						else cur *= 8;
					}
					curS += cur;
				}
				ans += curS;
				continue;
			}
			ll cur=1;
			for(int k=i+1; k<sn; ++k){
				if(k == 1){
					cur *= 9;
				}
				else {
					cur *= 8;
				}
			}
			ans += cur;
		}
		if(i>=1 && s[i-1]==s[i]){
			break;
		}
		if(i>=2 && s[i-2]==s[i]){
			break;
		}
		if(i == sn-1) ++ans;
	}
	for(int i=0; i<sn; ++i) s[i]=0;
	return ans;
}
int main(){
	ll a,b;
	read(a,b);
	ll ans = f(b);
	if(a) ans -= f(a-1);
	printf("%lld\n", ans);
	return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
