Submission #648462

#TimeUsernameProblemLanguageResultExecution timeMemory
648462glomePalindrome-Free Numbers (BOI13_numbers)C++17
39.17 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; string num; int dp[19][11][11][2]; int mod = 1e9 + 7; int rec(int pos, int p1, int p2, int f) { if(pos == num.size()) return 1; if(dp[pos][p1][p2][f] != -1) return dp[pos][p1][p2][f]; int LIM = 9; if(!f) LIM = num[pos] - '0'; int res = 0; for (int i = 0; i<=LIM; i++) { if(p1 == i || p2 == i) continue; res += rec(pos+1, i, p1, (f || i < LIM)); if(res >= mod) res -= mod; } return dp[pos][p1][p2][f] = res; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long A, B; cin >> A >> B; num = to_string(B); if(A == 0) { memset(dp, -1 ,sizeof(dp)); cout << rec(0, 10, 10, 0) << '\n'; } else { A--; memset(dp, -1 ,sizeof(dp)); B = rec(0, 10, 10, 0); memset(dp, -1, sizeof(dp)); num = to_string(A); cout << B - rec(0, 10, 10, 0) << '\n'; } return 0; }

Compilation message (stderr)

numbers.cpp: In function 'int rec(int, int, int, int)':
numbers.cpp:13:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if(pos == num.size()) return 1;
      |        ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...