답안 #779874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779874 2023-07-12T01:56:08 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++17
1.25 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 1e5 + 5, mod = 1e9 + 7, inf = 1e18;
ll dp[20][12][12][2];
ll bachtrach(string &lim, int ith, int last1, int last2, bool smaller)
{
	if(ith == lim.size()) return 1;

	if(dp[ith][last1+1][last2+1][smaller] != -1)
	{
		return dp[ith][last1+1][last2+1][smaller];
	}
	int curdig = lim[ith]-'0';
	ll ans = 0;
	// if(last1 == -1)
	// {
	// 	if(curdig == 0) ans += bachtrach(lim, ith + 1, 0, last1, 0);
	// 	else ans += bachtrach(lim, ith + 1, 0, last1, 1);
	// }
	if(smaller)
	{
		for(int i = 0; i <= 9; ++i)
		{
			if(i != last1 && i != last2) ans += bachtrach(lim, ith + 1, i, last1, 1);
		}
	}
	else
	{
		for(int i = 0; i < curdig; ++i)
		{
			if(i != last1 && i != last2) ans += bachtrach(lim, ith + 1, i, last1, 1);
		}
		ans += bachtrach(lim, ith + 1, curdig, last1, 0);
	}
	return dp[ith][last1+1][last2+1][smaller] = ans;
}
ll slove(ll x)
{
	string lim = to_string(x);
	memset(dp, -1, sizeof(dp));
	return bachtrach(lim, 0, -1, -1, 0);
}
int main()
{
	// freopen(".INP", "r", stdin);
	// freopen(".OUT", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	ll a, b;
	cin >> a >> b;
	cout << slove(b) - slove(a - 1) + 1;		    
}

Compilation message

numbers.cpp: In function 'long long int bachtrach(std::string&, int, int, int, bool)':
numbers.cpp:8:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  if(ith == lim.size()) return 1;
      |     ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 0 ms 340 KB Output isn't correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 300 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 0 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 0 ms 340 KB Output isn't correct
21 Incorrect 0 ms 340 KB Output isn't correct
22 Incorrect 0 ms 340 KB Output isn't correct
23 Incorrect 0 ms 340 KB Output isn't correct
24 Incorrect 0 ms 340 KB Output isn't correct
25 Incorrect 0 ms 340 KB Output isn't correct
26 Incorrect 0 ms 340 KB Output isn't correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Incorrect 1 ms 340 KB Output isn't correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Incorrect 1 ms 340 KB Output isn't correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Incorrect 1 ms 340 KB Output isn't correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 1 ms 340 KB Output isn't correct
37 Incorrect 1 ms 340 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 340 KB Output isn't correct
40 Incorrect 1 ms 340 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 1 ms 340 KB Output isn't correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 0 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct