Submission #703847

# Submission time Handle Problem Language Result Execution time Memory
703847 2023-02-28T17:00:45 Z Doncho_Bonboncho Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 352 KB
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int MAX_N = 1e6;
const int INF = 1e9;
const int mod = 1e9 + 7;

int inp[MAX_N];

ll dp[25][11][11][2];

ll sol( int n, int a, int b, bool st ){

	ll& nas = dp[n][a][b][st];
	if( ~nas ) return nas;
	if( inp[n] == 10 ) return nas = 1;

	nas = 0;

	for( int i=0 ; i <= ( st ? 9 : inp[n] ) ;  i++ ){

		if( i == a || i == b ) continue;

		if( i == 0 and a == 10 and b == 10 ) nas += sol( n+1, a, b, true );
		else nas += sol( n+1, i, a, ( st || ( i != inp[n]) ) );
	}

	return nas;
}

ll get( ll a ){

	/*
	for( int i=0 ; i<a.size() ; i++ ) inp[i] = a[i] - '0';
	inp[a.size()] = 10;
	*/
	int size = 0;
	ll A = a;
	while( A ){
		size++;
		A/=10;
	}

	for( int i = size-1 ; i>=0 ; i-- ){
		inp[i] = a%10;
		a/=10;
	}
	inp[size] = 10;

	/*
	for( int i=0 ; i<=size ; i++ ) std::cout<<inp[i]<<" ";
	std::cerr<<"\n";
	*/

	std::memset( dp, -1, sizeof(dp) );

	return sol( 0, 10, 10, false );
}

int main () {

	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);

	ll a, b;
	std::cin>>a>>b;
	std::cout<<get(b) - get(a-1);
	

	return 0;
}
# 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 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is 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 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 352 KB Output is correct
27 Correct 1 ms 340 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 340 KB Output is correct
31 Correct 1 ms 328 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 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 328 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 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct