Submission #832073

#TimeUsernameProblemLanguageResultExecution timeMemory
832073allwPalindrome-Free Numbers (BOI13_numbers)C++17
37.92 / 100
1 ms340 KiB
#include <algorithm> #include <cstdio> #include <vector> #include <iostream> #include <map> #include <cstring> #define LOCAL true /* Author: Oleksii Renov */ using namespace std; using ll = long long int; int dp[20][11][11][2][2]; ll run(int pos, int last1, int last2, bool smaller, bool started, const string& x) { if (pos == x.size()) { return 1; } if (dp[pos][last1][last2][smaller][started] != -1) { return dp[pos][last1][last2][smaller][started]; } int end = smaller ? 9 : (x[pos] - '0'); ll cnt = 0; for (int i = 0; i <= end; ++i) { if (!started && i == 0) continue; if (i != last1 && i != last2) { cnt += run(pos + 1, i, last1, smaller || (i != end), started || (i != 0), x); } } dp[pos][last1][last2][smaller][started] = cnt; return cnt; } int main() { ll a, b; cin >> a >> b; memset(dp, -1, sizeof(dp)); ll cnt1 = run(0, 10, 10, false, false, to_string(b)); memset(dp, -1, sizeof(dp)); ll cnt2 = run(0, 10, 10, false, false, to_string(a-1)); std::cout << cnt1 - cnt2 << '\n'; }

Compilation message (stderr)

numbers.cpp: In function 'll run(int, int, int, bool, bool, const string&)':
numbers.cpp:20:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     if (pos == x.size()) {
      |         ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...