Submission #1121067

#TimeUsernameProblemLanguageResultExecution timeMemory
1121067vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms508 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define int long long using namespace std; const int sz = 20; int dp[sz][sz][sz][2]; string s; int f(int ind, int prv, int prv2, bool same) { if(dp[ind][prv][prv2][same] != -1) return dp[ind][prv][prv2][same]; if(ind == s.size()) return 1; int ans = 0; for(int i = 0; i <= 9; i++) { if((i > s[ind] - '0' && same) || i == prv || i == prv2) continue; int val = i; if(prv == 10 && i == 0) val = 10; if(i == s[ind] - '0') { ans += f(ind + 1, val, prv, same); } else { if(same) { if(s[ind] - '0' > i) ans += f(ind + 1, val, prv, !same); } else { ans += f(ind + 1, val, prv, same); } } } return dp[ind][prv][prv2][same] = ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int l, r; cin >> l >> r; memset(dp, -1, sizeof(dp)); s = to_string(r); r = f(0, 10, 10, 1); if(l > 0) { memset(dp, -1, sizeof(dp)); s = to_string(l - 1); l = f(0, 10, 10, 1); } cout << r - l; }

Compilation message (stderr)

numbers.cpp: In function 'long long int f(long long int, long long int, long long int, bool)':
numbers.cpp:13:12: 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]
   13 |     if(ind == s.size()) return 1;
      |        ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...