Submission #547252

#TimeUsernameProblemLanguageResultExecution timeMemory
547252JomnoiPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms392 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; long long dp[20][2][2][11][11]; long long solve2(string s, int idx = 0, bool f = false, bool lead0 = true, int p1 = 10, int p2 = 10) { if(dp[idx][f][lead0][p1][p2] != -1) { return dp[idx][f][lead0][p1][p2]; } if(idx == s.size()) { return 1; } int len = 9; if(f == false) { len = s[idx] - '0'; } long long res = 0; for(int i = 0; i <= len; i++) { if(i == p1 or i == p2) { continue; } bool nf = f, nlead0 = lead0; int np1 = i, np2 = p1; if(i < len) { nf = true; } if(i != 0) { nlead0 = false; } if(nlead0 == true) { np1 = np2 = 10; } res += solve2(s, idx + 1, nf, nlead0, np1, np2); } return dp[idx][f][lead0][p1][p2] = res; } long long solve(long long a) { for(int i = 0; i < 20; i++) { for(int j = 0; j <= 10; j++) { for(int k = 0; k <= 10; k++) { dp[i][0][0][j][k] = dp[i][1][0][j][k] = -1; dp[i][0][1][j][k] = dp[i][1][1][j][k] = -1; } } } string t; while(a > 0) { t.push_back(a % 10 + '0'); a /= 10; } reverse(t.begin(), t.end()); return solve2(t); } int main() { cin.tie(0)->sync_with_stdio(0); long long a, b, ans; cin >> a >> b; ans = solve(b); if(a > 0) { ans -= solve(a - 1); } cout << ans; return 0; }

Compilation message (stderr)

numbers.cpp: In function 'long long int solve2(std::string, int, bool, bool, int, int)':
numbers.cpp:11:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if(idx == s.size()) {
      |        ~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...