Submission #723788

#TimeUsernameProblemLanguageResultExecution timeMemory
723788JuanPalindrome-Free Numbers (BOI13_numbers)C++17
73.75 / 100
1 ms304 KiB
#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)

numbers.cpp: In function 'long long int solve(long long int)':
numbers.cpp:15: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]
   15 |  for(int i = 1; i < s.size(); i++){
      |                 ~~^~~~~~~~~~
numbers.cpp:23: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]
   23 |   if(i==s.size()-1) rt++;
      |      ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...