Submission #648480

#TimeUsernameProblemLanguageResultExecution timeMemory
648480glomePalindrome-Free Numbers (BOI13_numbers)C++17
66.67 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; string num; int dp[19][11][11][2][2]; int mod = 1e9 + 7; int rec(int pos, int p1, int p2, int f, int ok) { if(pos == num.size()) return 1; if(dp[pos][p1][p2][f][ok] != -1) return dp[pos][p1][p2][f][ok]; int LIM = 9; if(!f) LIM = num[pos] - '0'; int res = 0; for (int i = 0; i<=LIM; i++) { if(ok) { if(i == p1 || i == p2) continue; res += rec(pos+1, i, p1, (f || i < LIM), 1); } else res += rec(pos+1, (i == 0 ? 10 : i), p1, (f || i < LIM), (i != 0)); if(res >= mod) res -= mod; } return dp[pos][p1][p2][f][ok] = 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,0) << '\n'; } else { A--; memset(dp, -1 ,sizeof(dp)); B = rec(0, 10, 10, 0,0); memset(dp, -1, sizeof(dp)); num = to_string(A); cout << (B - rec(0, 10, 10, 0, 0) + mod) % mod << '\n'; } return 0; }

Compilation message (stderr)

numbers.cpp: In function 'int rec(int, 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...