Submission #1101711

# Submission time Handle Problem Language Result Execution time Memory
1101711 2024-10-16T16:39:26 Z jinhan814 Palindrome-Free Numbers (BOI13_numbers) C++17
96.25 / 100
2 ms 508 KB
#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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 508 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 504 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 504 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct