Submission #1101711

#TimeUsernameProblemLanguageResultExecution timeMemory
1101711jinhan814Palindrome-Free Numbers (BOI13_numbers)C++17
96.25 / 100
2 ms508 KiB
#include <bits/stdc++.h> #define fastio cin.tie(0)->sync_with_stdio(0) using namespace std; using i64 = long long; template<typename T> auto vectors(const int n, T&& val) { return vector(n, val); } template<typename... Ts> auto vectors(const int n, Ts&&... args) { return vector(n, vectors(args...)); } auto f = [](i64 n) { if (n < 0) return 0LL; string s = to_string(n); vector dp = vectors(s.size(), 11, 11, 2, -1LL); auto rec = [&](const auto& self, int i, int a, int b, int f) -> i64 { if (i < 0) return 1; i64& ret = dp[i][a][b][f]; if (ret != -1) return ret; ret = 0; for (int x = 0; x < 10; x++) { if (x == a || x == b) continue; if (!f && x > s[s.size() - 1 - i] - 48) continue; int nf = f || (x < s[s.size() - 1 - i] - 48); ret += self(self, i - 1, b, x, nf); } return ret; }; i64 res = 0; for (int i = 0; i < s.size(); i++) { int f = i + 1 < s.size(); res += rec(rec, i, 0, 10, f); } return res; }; int main() { fastio; i64 a, b; cin >> a >> b; cout << f(b) - f(a - 1) << '\n'; }

Compilation message (stderr)

numbers.cpp: In lambda function:
numbers.cpp:24:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   24 |   if (ret != -1) return ret; ret = 0;
      |   ^~
numbers.cpp:24:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   24 |   if (ret != -1) return ret; ret = 0;
      |                              ^~~
numbers.cpp: In lambda function:
numbers.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
numbers.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   int f = i + 1 < s.size();
      |           ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...