| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1352101 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++20 | 1 ms | 344 KiB |
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2,lzcnt,bmi,bmi2")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
int get(int n) {
if (n < 0) {
return 0;
} else {
if (n == 0) {
return 1;
}
string y = to_string(n);
int ans = 1;
for (int j = 1; j < y.size(); j++) {
int pr = 1;
for (int e = 1; e <= j && e <= 2; e++) {
pr *= 9;
}
for (int e = 3; e <= j; e++) {
pr *= 8;
}
ans += pr;
}
for (int pref = 0; pref < y.size(); pref++) {
int lvl = y[pref] - '0';
for (int cur = (pref == 0); cur < lvl; cur++) {
string e = y.substr(0, pref);
e += (cur + '0');
bool ch = 1;
for (int t = 1; t < e.size(); t++) {
if (e[t] == e[t - 1]) {
ch = 0;
}
}
for (int t = 2; t < e.size(); t++) {
if (e[t] == e[t - 2]) {
ch = 0;
}
}
if (ch) {
int tt = 1;
for (int sz = pref + 1; sz < y.size(); sz++) {
if (sz <= 1) {
tt *= 9;
} else {
tt *= 8;
}
}
ans += tt;
// cout << e << ' ' << tt << endl;
}
}
}
bool ch = 1;
for (int i = 1; i < y.size(); i++) {
if (y[i] == y[i - 1]) {
ch = 0;
}
}
for (int i = 2; i < y.size(); i++) {
if (y[i] == y[i - 2]) {
ch = 0;
}
}
// cout << y << ' ' << ch << endl;
return ans + ch;
}
}
void gogo() {
int a, b;
cin >> a >> b;
// cout << get(a) << endl;
cout << get(b) - get(a - 1) << endl;
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
gogo();
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
