Submission #723802

# Submission time Handle Problem Language Result Execution time Memory
723802 2023-04-14T10:29:59 Z Juan Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 240 KB
#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 = 0;
	string s = to_string(n);
	for(int i = 1; i < s.size(); i++){
		int val, sz = s.size()-i;
		if(sz>=2) val = 81 * pow(8, sz-2);
		else if(sz==1) val = 10;
		rt += val;
	}


	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 += (ni -(nii<ni) -(niii<ni)) * 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

numbers.cpp: In function 'long long int solve(long long int)':
numbers.cpp:12:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 1; i < s.size(); i++){
      |                 ~~^~~~~~~~~~
numbers.cpp:22:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 1; i < s.size(); i++){
      |                 ~~^~~~~~~~~~
numbers.cpp:30:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(i==s.size()-1) rt++;
      |      ~^~~~~~~~~~~~
numbers.cpp:16:6: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |   rt += val;
      |   ~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 240 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct