#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define f first
#define s second
#define DEBUG(a, b) cerr<<a<<b;
pair<long long, bool> check(long long s) {
long long prev = -1, pprev = -2;
long long c = 1, n = 0, k = 0;
while(s > 0) {
if(s%10 == prev)return {n%(c/10) + 1, 1};
else if(s%10 == pprev)return {n%(c/100)+1, 1};
pprev = prev;
prev = s%10;
n+=s%10 * c;
s/=10;
c*=10;
}
return {1, 0};
}
int main () {
long long a, b, c = 0;
cin >> a >> b;
long long k = b-a;
while(b >= a) {
pair<long long, bool> k = check(b);
if(k.s)c+=min(k.f, b-a + 1);
b-=k.f;
}
cout<<k - c+1;
}
Compilation message
numbers.cpp: In function 'std::pair<long long int, bool> check(long long int)':
numbers.cpp:12:30: warning: unused variable 'k' [-Wunused-variable]
12 | long long c = 1, n = 0, k = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
3 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
268 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
3 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
4 |
Execution timed out |
1099 ms |
204 KB |
Time limit exceeded |
5 |
Correct |
729 ms |
268 KB |
Output is correct |
6 |
Correct |
753 ms |
324 KB |
Output is correct |
7 |
Correct |
38 ms |
264 KB |
Output is correct |
8 |
Correct |
27 ms |
284 KB |
Output is correct |
9 |
Correct |
48 ms |
268 KB |
Output is correct |
10 |
Correct |
66 ms |
280 KB |
Output is correct |
11 |
Correct |
75 ms |
204 KB |
Output is correct |
12 |
Correct |
433 ms |
204 KB |
Output is correct |
13 |
Correct |
104 ms |
204 KB |
Output is correct |
14 |
Correct |
724 ms |
280 KB |
Output is correct |
15 |
Correct |
843 ms |
264 KB |
Output is correct |
16 |
Execution timed out |
1092 ms |
204 KB |
Time limit exceeded |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Execution timed out |
1095 ms |
204 KB |
Time limit exceeded |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Execution timed out |
1094 ms |
204 KB |
Time limit exceeded |
26 |
Execution timed out |
1092 ms |
296 KB |
Time limit exceeded |
27 |
Execution timed out |
1065 ms |
204 KB |
Time limit exceeded |
28 |
Execution timed out |
1089 ms |
204 KB |
Time limit exceeded |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Execution timed out |
1075 ms |
204 KB |
Time limit exceeded |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Execution timed out |
1094 ms |
204 KB |
Time limit exceeded |
36 |
Execution timed out |
1040 ms |
204 KB |
Time limit exceeded |
37 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |
38 |
Execution timed out |
1091 ms |
204 KB |
Time limit exceeded |
39 |
Execution timed out |
1096 ms |
204 KB |
Time limit exceeded |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Execution timed out |
1097 ms |
204 KB |
Time limit exceeded |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |
44 |
Execution timed out |
1064 ms |
204 KB |
Time limit exceeded |
45 |
Execution timed out |
1044 ms |
204 KB |
Time limit exceeded |